I have a class A, which has two functions (“Download” and “query”). When the function “Download” is finished, it will fire the “finish” event. Since the function “query” will use the return info from the finished “Download” function, I want when function “query” is called from a class outside A (e.g., Class B), the function will wait to execute until the “Download” is finished. Class B won’t recognize “query” function in A is waiting on the “Download” finish. In other words, I don’t want in class B’s download finish event handler to call the “query” function.
Class A
{
public Event finish;
public A()
{
Download();
}
private void Download ()
{
finish(this, new EventArgs());
}
public void query ()
{
}
}
Class B
{
A a = new A();
a.query();
}
Thanks,
Wei
You have to synchronize the methods Download and query. Therefore you can use AutoResetEvents:
This will hold on every thread that enters the method Query until the reset event is set.
But if Download is run synchronously, you don’t have to synchronize them. As the constructor of A is called from B, B cannot call query before Download has finished.