Event in a Thread
-
Hello I have created my own event and delegate, they look like this:
public delegate Answer delegateCallResponse(Request req); public event delegateCallResponse eventCallResponse;
the Request and Answer is 2 struct which contain a few strings/ints. I got a method to handle the event, which look like
public Answer ans = new Answer(); private Answer OnEvent(Request req) { FillRequest(req); while (!ans.filled) { Thread.Sleep(1000); } return this.ans; }
the
ans.filled
is a bool indication whether the information is filled or not. My problem is that the Answer can take a while to get filled and the code as it is now, will make the mainthread sleep thus making the GUI unavailable for some time. Is there a way to run the event in a thread? or just another way to make it wait than use the while function? //QzRz -
Hello I have created my own event and delegate, they look like this:
public delegate Answer delegateCallResponse(Request req); public event delegateCallResponse eventCallResponse;
the Request and Answer is 2 struct which contain a few strings/ints. I got a method to handle the event, which look like
public Answer ans = new Answer(); private Answer OnEvent(Request req) { FillRequest(req); while (!ans.filled) { Thread.Sleep(1000); } return this.ans; }
the
ans.filled
is a bool indication whether the information is filled or not. My problem is that the Answer can take a while to get filled and the code as it is now, will make the mainthread sleep thus making the GUI unavailable for some time. Is there a way to run the event in a thread? or just another way to make it wait than use the while function? //QzRz -
Hello I have created my own event and delegate, they look like this:
public delegate Answer delegateCallResponse(Request req); public event delegateCallResponse eventCallResponse;
the Request and Answer is 2 struct which contain a few strings/ints. I got a method to handle the event, which look like
public Answer ans = new Answer(); private Answer OnEvent(Request req) { FillRequest(req); while (!ans.filled) { Thread.Sleep(1000); } return this.ans; }
the
ans.filled
is a bool indication whether the information is filled or not. My problem is that the Answer can take a while to get filled and the code as it is now, will make the mainthread sleep thus making the GUI unavailable for some time. Is there a way to run the event in a thread? or just another way to make it wait than use the while function? //QzRz