Hi,
a possible solution would be, that you use a static (shared) variable which can be accessed by multiple threads.
Here is a small example of what I mean:
public class ProcessingClass
{
private static volatile object _lock = new object();
private static Thread _workerThread;
public void StartProcessing()
{
lock (_lock)
{
if (_workerThread != null)
{
throw new NotSupportedException("The thread is already processing...");
}
_workerThread = new Thread(ProcessingMethod);
_workerThread.Start();
}
}
public void EndProcess()
{
lock (_lock)
{
if (_workerThread == null)
{
throw new NotSupportedException("The thread is not processing anything.");
}
_workerThread.Join(1000);
}
}
public void ProcessingMethod()
{
Thread.Sleep(10000);
}
}
The
ProcessingClass
can be any class you want, it could also be the ASP.NET Page, that should not matter.
Hope this helps!
Best regards and happy coding,
Chris