sbatch

I have a data collection program that I want to be able to abort out of using a form button but while the program runs through it's loops I lose focus to the form so the button does not work. How do I bring focus back to the form so the button works, and will I lose focus again as I move through my program I do not want to end the program, just stop it since I have some bookkeeping I need to take care of after I abort the program.

Re: Visual Basic General getting focus to the form

cybertaz69

You are only using one thread so you loops are taking all the CPU time.  What you need to do is put the loops in a background thread so the form can still respond to click and other events.  Using VB2005 backgroundworker, you can create multi thread apps.




Re: Visual Basic General getting focus to the form

sbatch

Sorry I have not gotton back earlier. I finally had a chance to add the thread. That worked great! I was also able to use an invoke call to update my status label on my form while the thread is running. I have another section of code that changes some labels and label formats on my main form when the program runs. I don't see an easy way to use invoke delegate on that. I was not able to figure out how to change those while my backgroundworker is running. Right now I have set CheckForIIlegalCrossThreadCalls set to false but I know that could be dangerous. Any suggestions