LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2005, 07:52 PM   #1
jwn7
Member
 
Registered: Aug 2004
Location: pittsburgh, pa
Distribution: gentoo
Posts: 81

Rep: Reputation: 15
VERY strange C# event handling problem, please read.


Hi

I'm hesitant to post this here, but I know a lot of good programmers are around and I _need_ help with this one. I've been using C# for all of 3 days, and it's actually not too bad minus well ... yeah.

I'm writing a simple app in C# that communicates with an activeX control for a fingerprint reader. In my app, I call a function of the activeX control, then I have to sit and wait for the corresponding event to happen before i can continue executing, or I won't get the correct result from the reader.

To do this waiting, I used an AutoResetEvent. Right after I call the control's function, I say wait for an autoevent to be signaled. In the event handler function, I set the autoevent.

This works absolutely perfect for every event except one, and I can't figure out why. The event handler for one event doesn't run (yes I have the event += event_handler thing in the windows forms code.

Code:
public string Identify()  {
    bioPlugin.IdentifyQuick();     // activeX control's function
    signals.identify.WaitOne();   // wait for the event
    return result;                     // now result is what it should be
}
private void bioPlugin_OnIdentify(object sender, System.EventArgs e) {
    SetResult();                     // store the result somewhere
    signals.identify.Set();        // set the signal
}
This works perfect. Some other form calls the Identify() function when a button is clicked. The Identify() function calls the IdentifyQuick() method of the active X control, and we sit and wait until the identify signal is set. This signal is set when the event handler for that event executes. Everything is great.

Code:
public void Register(string name)  {
    bioPlugin.RegisterSinglePrint(name);  // activeX control's

    // MessageBox.Show("if we do this, everything works");

    //  this should work and it doesn't. something is borked.
    signals.register.WaitOne();  // waits forever
}
// this code never runs.
// it's linked to the event and it should run - the other events work fine
private void bioPlugin_OnRegister(object sender, System.EventArgs e) {
    SetResult();
    signals.register.Set();
}
This is the exact same thing here. The Register() function is called when a button is clicked, we call the RegisterPrint() function of the activeX control, and sit and wait on the right signal. However, it sits here forever and the event handler code just flat out doesn't run. It's not a bug in the activeX control, it works just fine in VB and the activeX tester thing. And I really think I have everything right.

Down at the bottom I do have
Code:
this.bioPlugin.OnRegister += new System.EventHandler(this.bioPlugin_OnRegister);
this.bioPlugin.OnIdentify += new System.EventHandler(this.bioPlugin_OnIdentify);
so the event handlers are linked to the events. What's really really bizzare is if I show a message box in between calling the active X control and the waiting, everything works.

WTF is going on here?? I need either a) a way to fix this b) a way to do what ever the message box does without the user seeing a message box or c) an entirely different way of waiting for these event's to execute.

Thanks for reading, any help is greatly appreciated as I'm at a loss. Could it possibly be a bug in .NET or the threading model or something like that? I really think it's my code but I'm out of ideas.
 
Old 10-20-2005, 02:07 AM   #2
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
Look buddy this is not the case that there is a bug in .Net may be there is some problem somewhere in your code or configuration. You should do a little debugging. Try out these.
inter-change your events and event handlers like

this.bioPlugin.OnRegister += new System.EventHandler(this.bioPlugin_OnIdentify);
this.bioPlugin.OnIdentify += new System.EventHandler(this.bioPlugin_OnRegister);

Now OnRegister function will be called on OnIdentify Event and vice versa. This will confirm you that either you have problem in generating the event or there is a problem in Event handler.
It may be the case that your code

bioPlugin.RegisterSinglePrint(name);

does not generates a message. There maybe some problem in its source code. Because the implementation of the function RegisterSinglePrint() must Post a Message to the queue and then your event handler will be called. If there is a problem in it and it is not generating the message or generation the wrong message...........
 
Old 10-20-2005, 10:28 AM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
I wouldn't completely rule out the idea of a bug, but I would try to investigate the problem thoroughly first to see if it was your code. In particular, I have seen a number of strange things when using the COM to .Net interop layer that gets generated.

If the COM control you are using is one you wrote yourself, try using a debug build of it and try stepping through the function that should be generating an event. If it is not your own COM control, you might try writing a Managed C++ app to act as your own Interop layer.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP w/: Script for EVENT Handling!!! vitoal18t Programming 2 06-24-2009 02:36 PM
pygtk event handling pita Programming 1 10-20-2005 01:48 PM
Need help handling a dial-in event GD_19 Linux - Networking 0 01-30-2004 12:19 AM
Has Samba some event handling possibility? vmicho Linux - Networking 1 11-03-2003 01:44 PM
Strange password handling.. Halz Linux - General 5 06-19-2003 02:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration