I am using the following code to do what I ask:
private delegate void CallerDelegate(object e);
CallerDelegate caler = new CallerDelegate(MethodToCall);
when the button is clicked:
if (currBusyThrd != null && currBusyThrd.IsAlive)
{
currBusyThrd.Abort();
}
ThreadPool.SetMaxThreads(1, 1);
ThreadPool.QueueUserWorkItem(new WaitCallback(WaitCallbackMethod))
WaitCallbackMethod Method:
void WaitCallbackMethod(object stateInfo)
{
BeginInvoke(caler,argList);
}
and the method that I call downstream is as follows:
void MethodToCall(object args)
{
currBusyThrd = Thread.CurrentThread;
}
I feel this is wrong ... How to do it right?
In fact, the call will be executed using TextBox_KeyUp .. so every time the user enters a char, the code will be executed again .. and BackgroundWorker does not work.
source
share