'Simple' Kill button/progress bar problem

A

AE_Cory

I'm a n00b to Visual C++ and OOP, but not to programming in general.

Here's the problem: Not knowing what I'm doing, I've made my VC++
application as a CLR Window Forms project. Now, I have a process that
is lauched by pushing a button. The code for this process is inside
the Button_Click event handler for that particular button.

The problem is that I need to be able to kill that process with another
button. I have a global flag that would kick out of that process, and
that flag is changed in the Kill button event handler. But I can't
actually use that button when I need to, because when the process is
running it's still technically inside the event handler for the "Go"
button click.

I've even started a second thread with ThreadPool to house this
process. Now, I can supposedly do what I need, but I can't tell if I
need it because the progressBar that I'm using in my UI can't be used
by the new process thread. If I put code in the main thread to move
the progressBar based on another global variable, I once again can't
use the Kill button because I'm stuck back in the Go Button_Click event
handler.

I've posted this question before and all of the responses that I
recieved utilized message pump - type ways of handling this, but since
I made this with the CLR windows form designer, I don't have access to
that part of the program - CLR hides that all away.

I also can't find a convenient Idle process in the Forms class.

Is there an easy way to accomplish this with the CLR resources? If
not, is there some way to design the UI graphically but then use the
MFC or the Windows API? I'd rather not have to redo my UI in code just
because I can't get the Kill button and progressbar to work at the same
time.

Thanks in advance,

-Cory
 
B

Ben Voigt

I've posted this question before and all of the responses that I
recieved utilized message pump - type ways of handling this, but since
I made this with the CLR windows form designer, I don't have access to
that part of the program - CLR hides that all away.

Not at all. You can override the WndProc method in your form.

You can also use Control.Invoke, which .NET probably implements by sending a
message, to allow your worker threads to run snippets of code back in the UI
thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top