You can organize it yourself, just make sure your thread method called the completed method (or event) when it was done.
Since CF does not support the ParameterizedThreadStart parameter, I once made a small helper class.
The following is a snippet and has not been re-tested:
public abstract class BgHelper
{
public System.Exception Error { get; private set; }
public System.Object State { get; private set; }
public void RunMe(object state)
{
this.State = state;
this.Error = null;
ThreadStart starter = new ThreadStart(Run);
Thread t = new Thread(starter);
t.Start();
}
private void Run()
{
try
{
DoWork();
}
catch (Exception ex)
{
Error = ex;
}
Completed();
}
protected abstract void DoWork() ;
protected abstract void Completed();
}
You need to inherit and execute DoWork and Completed. It would probably make sense to use <T> for state ownership, just noticed that.
source
share