0

Hey,
I wanna use OpenReadAsync instead of OpenRead because its blocking my Form....

But i cant get it work....

Ok... Im programming in C++/Cli but its not rly different.

IO::StreamReader^ sr = gcnew IO::StreamReader(webClientOther->OpenReadAsync(gcnew Uri("Site")));

In C#?

IO.StreamReader^ sr = new IO.StreamReader(webClientOther.OpenReadAsync(new Uri("Site")));

I hope I "translated" it right...

But then the error appears: "Cannot convert void to System::IO::Stream".

Hope someone can help me :D.
You can post the right code in C# ;).

THANKS :D

2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by Ultratermi
0

>But then the error appears: "Cannot convert void to System::IO:tream

Because of its signature - void OpenReadAsync()

Have a look,

void readCompleted(System::Object^  sender, System::Net::OpenReadCompletedEventArgs  ^  e) {
	
	Console::WriteLine("Data: " + e->Cancelled);
	Console::WriteLine("Object : " + e->UserState);
	IO::StreamReader^ sr=gcnew IO::StreamReader(e->Result);
 	.....
	
}
	
int main(array<System::String ^> ^args)
{
  	WebClient^ wc=gcnew WebClient();
	wc->UseDefaultCredentials=true;
	wc->OpenReadCompleted+=gcnew  OpenReadCompletedEventHandler(&readCompleted);
	wc->OpenReadAsync(gcnew Uri("http://x/y/z.txt",UriKind::Absolute),gcnew Object());
	while(wc->IsBusy)
	{

	}
	
    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.