hard key interface problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a multi-form app that uses the hard keys and context menus to complete
tasks. When the context menu is used to start a task, there are no problems.
However, if the hard keys are used to start the same task it always has
problems.

In my main form, a thread is started that constantly polls the keys for
changes. The main form also contains a list view. One of the items must be
selected in the list view before any action is performed (via menu or
button). The user must select one of the items in the list view and when a
button (or menu item) is pushed an event is fired from the class that manages
the key polling (in a different thread). The main form hides and passes the
information about the selected item to another class (CommandProcessor) which
sets up another form and displays it. Once the user has completed the
actions on this form and pressed OK or Cancel the result is returned to the
class that created the form. Information is then processed from the result
of the form that was just closed and the result of this process is then
returned to the main form. The main form processes the received information
and then changes the Text property to the correct name. The listview is
updated to reflect any changes from the other form.

This process works fine when the process is begun with the context menu, but
fails by not reloading the main form.

I think it has something to do with the different threads, but I'm not
certain. Has anyone had any experience with this or have any idea what might
be causing the problem?

Thanks
-G
 
Why don't you post a reproducible sample so we can look at it?

Generic advice. ContextMenu has some issues:
http://www.danielmoth.com/Blog/2004/11/contextmenushow.html

Never touch UI controls from threads other than the one that created them
(use Control.Invoke instead). Even though this implies you can create a form
from a user created thread (not the main thread running Application.Run),
usually this leads to problems so the advice is not to do that.

Cheers
Daniel
 
I've posted a sample project at:

http://www.geocities.com/tigerqt/HardKeyTest.zip

It's a really simple program. I'm almost completely certain that it's a
threading issue, but I'm not sure how to circumvent the problem. This sample
shows a very basic idea of what is going on with my app.

Just load it up and hit one of the 4 hardkeys. It will display a new form
that will have a checkbox on it as well. If you checked the box on the main
form, this box will also be checked. When you hit OK, you will see that the
main form never comes back into view.

If anyone has any ideas on how to get around this, please let me know.

Thanks
-G
 
Can you try replacing your ButtonPushed function with the following
(untested):

private void ButtonPushed(){
this.Invoke(new EventHandler(ButtonPushed2));
}

private void ButtonPushed2(object s, EventArgs e)
{
this.Text = "";
bool check = Proc.ChangeCheck(this.checkBox1.Checked);

if (check)
this.Text = "Checked";
else
this.Text = "Not Checked";

MoveToFront();
UpdateGUI(check);
}


Cheers
Daniel
 
Back
Top