staying within a function, while giving focus back to the form.

  • Thread starter Thread starter klumsy
  • Start date Start date
K

klumsy

this may be a little difficult for me to explain the first time round,
but here goes.

i have a form. and a method like

public void doyourprocessing
{
....
}

well normally if you say have a button and call doyourprocessing, it
will run the function, then end, giving focus back to the form, and the
forms main windows message loop.

however in my case I want it to behave differently. i want to be able
to say inside here have a loop that says, do the forms main windows
messaging loop until a certian condition (i.e a variable becomes true)
, in order to keep execution inside this function.

the reason why i want to do this , and the context is:
there is a third party librqary which will call doyourprocessing, the
processing i have to do however requires user interaction.. i can
successfully do this by making another form and showing it modal inside
this function (since the function hasn't exited while the modal form si
open) because the modal form has its own messaging loop going on.
However i really want to have the functionality in my main form, not
having to put up another form.. my idea is someting like this (but it
doesn't work)

public void doyourprocess
{
while ( !processingcomplete)
Application.Doevents();
}

does anybody know the correct way to achieve what i am trying? will it
involve multiple threads, and mutexes and such?
 
The only part you didn't mention is what will call your third-party
library, and does that library do its work asynchronously... that is,
does it immediately return control to the caller and then only later
call "doyourprocess()"? So, the flow of control looks like this:

caller --> third-party library
caller <-- third-party library
....then later...
third-party library --> doyourprocess()
third-party-library <-- doyourprocess()

Or, does the third-party library return to the caller only after it
finishes its work, so the folow of control looks like this:

caller --> third-party library --> doyourprocess()
caller <-- third-party library <-- doyourprocess()

The two scenarious require different designs, but yes, both will
involve background threads.
 
Back
Top