Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Thread - Notify() and get back to the main activty/ thread

AlonAvivAlonAviv USMember ✭✭

Hi there,
I'm having some problems using thread and async methods.
I tried doing a simple socket connection and after failing to use async and await keywords I just used a thread. My code looks like this:
Thread t = new Thread(() =>
{
//Socket socket1 = new Socket();
Socket server = new Socket ("10.100.101.103", 13137);
socket1.ConnectAsync (server.RemoteSocketAddress);
});
t.Start();
This is the client code. The connection is being made and I can get to the client from the server. The problem is that the client is stuck on this thread and can't get forward. even though I tried adding "notify()" inside/outside the thread.

Thanks a lot, Alon.

Answers

  • MihaMarkicMihaMarkic SI ✭✭✭✭

    Doesn't the code below work?
    What Socket are you using?

    Socket server = new Socket ("10.100.101.103", 13137);
    await socket1.ConnectAsync (server.RemoteSocketAddress);
    
  • AlonAvivAlonAviv USMember ✭✭

    cannot await a void (because of the connectAsync method).
    Also tried manipulate into Task version but it didn't work.

Sign In or Register to comment.