473,804 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading - need help making callback function a thread

Jim
I have a windows application that is accessing unmanaged
code and providing a callback function that will create
events at unknown time spans. When the EventHandler
(callback function) fires it causes my program to crash or
freeze, or do strange stuff. When I remove this callback
function it works great. Problem is I need this callback
function to implement my state machine for the program so
I think I need to encapsulate this callback function into
its own process, but it takes 4 parameters. I have looked
all over the web, but cannot find a good example of this
implementation can anyone point me in a good direction?
Nov 15 '05 #1
3 2045
Jim,

What is the mechanism that you are passing? Are you passing a COM
interface pointer, or are you passing a function pointer (which is marshaled
from a delegate into unmanaged code)? Each way has its own considerations,
but both are certainly doable.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jim" <je******@natio nsfirstcorp.com > wrote in message
news:02******** *************** *****@phx.gbl.. .
I have a windows application that is accessing unmanaged
code and providing a callback function that will create
events at unknown time spans. When the EventHandler
(callback function) fires it causes my program to crash or
freeze, or do strange stuff. When I remove this callback
function it works great. Problem is I need this callback
function to implement my state machine for the program so
I think I need to encapsulate this callback function into
its own process, but it takes 4 parameters. I have looked
all over the web, but cannot find a good example of this
implementation can anyone point me in a good direction?

Nov 15 '05 #2
Jim
I am sending a fucntion pointer. here is my Event Handler
Method. What is happening, is some how when my
eventhandler is fired it will lock up my program. I think
there is some memory issues here and I can't figure it
out.

unsafe public void EventHandler (void* vpUserData, uint
uiEvent, uint uiParam0, uint uiParam1)

{
EvQ[iQIn].uiUserData = (uint)vpUserDat a;

EvQ[iQIn].uiEvent = uiEvent;

EvQ[iQIn].uiParam0 = uiParam0;

EvQ[iQIn].uiParam1 = uiParam1;

richTextBox1.Ap pendText("\r\nE vent Handler " +
iQIn.ToString() );

richTextBox1.Ap pendText("\r\nE vent : " + uiEvent.ToStrin g
());

iQIn ++;

if(iQIn == 200) //Queue at max compacity

{

iQIn = 0; //Reset to 0

}

if(uiEvent == 215)

{

if(uiParam0== TONE_DIALTONE)

{

richTextBox1.Ap pendText("\r\n WE HAVE DIALTONE \r\n");

}

if(uiParam0 == TONE_RINGBACK)

{

richTextBox1.Ap pendText("\r\n WE HAVE RINGBACK \r\n");

}

if(uiParam0 == TONE_BUSY)

{

richTextBox1.Ap pendText("\r\n WE HAVE BUSY \r\n");

}

}
}
-----Original Message-----
Jim,

What is the mechanism that you are passing? Are you passing a COMinterface pointer, or are you passing a function pointer (which is marshaledfrom a delegate into unmanaged code)? Each way has its own considerations,but both are certainly doable.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jim" <je******@natio nsfirstcorp.com > wrote in message
news:02******* *************** ******@phx.gbl. ..
I have a windows application that is accessing unmanaged
code and providing a callback function that will create
events at unknown time spans. When the EventHandler
(callback function) fires it causes my program to crash or freeze, or do strange stuff. When I remove this callback function it works great. Problem is I need this callback function to implement my state machine for the program so I think I need to encapsulate this callback function into its own process, but it takes 4 parameters. I have looked all over the web, but cannot find a good example of this
implementation can anyone point me in a good direction?

.

Nov 15 '05 #3
I'll bet that your callback is being called on a thread other then the UI
thread. I think you should be using this.Invoke on any calls to your UI
controls.

Jeffrey
"Jim" <je******@natio nsfirstcorp.com > wrote in message
news:f5******** *************** *****@phx.gbl.. .
I am sending a fucntion pointer. here is my Event Handler
Method. What is happening, is some how when my
eventhandler is fired it will lock up my program. I think
there is some memory issues here and I can't figure it
out.

unsafe public void EventHandler (void* vpUserData, uint
uiEvent, uint uiParam0, uint uiParam1)

{
EvQ[iQIn].uiUserData = (uint)vpUserDat a;

EvQ[iQIn].uiEvent = uiEvent;

EvQ[iQIn].uiParam0 = uiParam0;

EvQ[iQIn].uiParam1 = uiParam1;

richTextBox1.Ap pendText("\r\nE vent Handler " +
iQIn.ToString() );

richTextBox1.Ap pendText("\r\nE vent : " + uiEvent.ToStrin g
());

iQIn ++;

if(iQIn == 200) //Queue at max compacity

{

iQIn = 0; //Reset to 0

}

if(uiEvent == 215)

{

if(uiParam0== TONE_DIALTONE)

{

richTextBox1.Ap pendText("\r\n WE HAVE DIALTONE \r\n");

}

if(uiParam0 == TONE_RINGBACK)

{

richTextBox1.Ap pendText("\r\n WE HAVE RINGBACK \r\n");

}

if(uiParam0 == TONE_BUSY)

{

richTextBox1.Ap pendText("\r\n WE HAVE BUSY \r\n");

}

}
}
-----Original Message-----
Jim,

What is the mechanism that you are passing? Are you

passing a COM
interface pointer, or are you passing a function pointer

(which is marshaled
from a delegate into unmanaged code)? Each way has its

own considerations,
but both are certainly doable.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jim" <je******@natio nsfirstcorp.com > wrote in message
news:02******* *************** ******@phx.gbl. ..
I have a windows application that is accessing unmanaged
code and providing a callback function that will create
events at unknown time spans. When the EventHandler
(callback function) fires it causes my program to crash or freeze, or do strange stuff. When I remove this callback function it works great. Problem is I need this callback function to implement my state machine for the program so I think I need to encapsulate this callback function into its own process, but it takes 4 parameters. I have looked all over the web, but cannot find a good example of this
implementation can anyone point me in a good direction?

.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2089
by: Jim West | last post by:
Good day all, Ok, I'm starting to get the hang of this Python thing...really pretty cool actually. Again, thanx to those that have helped me thus far. I now have another stumbling block to which I would like help. Ok, here is my enviroment: Windows 2K
5
4182
by: Francois De Serres | last post by:
Hiho, could somebody please enlighten me about the mechanics of C callbacks to Python? My domain is more specifically callbacks from the win32 API, but I'm not sure that's where the problem lies. Here's a description... I want a callback-based MIDI input/processing, so PortMidi was not an alternative. I have written a C extension module that links to the mmsys MIDI API. I separated the win32-dependant code from the Python extension...
77
5392
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go through the whole thing!) to check for accuracy, effectiveness of examples, etc. Feel free to mail...
8
8221
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd party COM component that takes about 5 seconds to run one of its functions (Network IO bound call). Since I dont want my GUI to freeze
3
4514
by: Asad | last post by:
Hi, I am trying to write some threading code to my application. The reason I've been tempted to do this is because, I am doing some FTP uploads, and sometimes during the put method, the application just hangs ("Not Responding") instead of the regular timeout and return. I am using a library to perform FTP stuff and so there may be a bug in there. In any case, what I am concerned with is my application executing with graceful execution...
0
2964
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode thread. so far so good. all contacts r added properly. now when another login adds me in his contact, i recv a subscription, so i popup a form and ask for accept/reject. this all happens in a separate thread. popup form gets opened and choice is...
5
1776
by: greg.merideth | last post by:
I have a class that I've provided an event for to be called when the processing in the class is complete (a callback). The class spins up a series of threads for the background operation and I'm firing the callback delgate from within one of the new threads. So far, all is well but I'm curious as to what, threading wise, is going on there. I'm instantiating the class in the app thread (say 1) and providing a method to call when...
9
1375
by: sreekant | last post by:
Hi folks What am I doing wrong in the following? I just want to run fluidsynth in the background. ######################################### class MyThread(threading.Thread): def __init__(self, cmd, callback): self.__cmd = cmd self.__callback = callback threading.Thread.__init__(self)
7
2379
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has finished. I am trying to follow this example : http://www.codeproject.com/cs/miscctrl/progressdialog.asp But although the messages still get moved, the progress window never does anything. Here is my code in full, if anybody who knows...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9171
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.