I'm trying to figure out how to set up an event that could be carried into a child process. I need this in order to calculate the time it took for the parent process to communicate with the child process. The code I've got is here: http://pastebin.com/euVfSNeg
The problem is that when the app2.exe calls app3.exe nothing happens, because the event doesn't get fired/listened (dont know which one is the case).
I need to figure this out ASAP as I've got to hand it in in a couple of hours.
Any help would be appreciated.
The MSDN page says:
lpEventAttributes A pointer to a SECURITY_ATTRIBUTES structure. If
this parameter is NULL, the handle cannot be inherited by child
processes.
A child process created by the CreateProcess function can inherit a
handle to an event object if the lpEventAttributes parameter of
CreateEvent enabled inheritance
And you're passing NULL as the first argument.
Related
This is a follow up/modification of my qn : Ptrace/wait on a non child
How do I ptrace or wait on a process that is not a child AND the process that waits is not a root user .
I tried to be in the same group, still doesnt work [ operation not permitted - to ptrace on a non-child ]
ptracing a process gives you complete control over it. If you could ptrace a process belonging to a different user, then users would be meaningless.
wait is specifically for parent notification.
You'll have to rethink your approach to whatever problem you're trying to solve.
I'm developing a simple win32 application with two processes sharing memory through a file mapping. At a certain point in the second process, I want to check if the other process has already closed the handle associated to the file mapping.
Is there a Windows function to retrieve the number of handles associated to my shared memory???
Thanks in advance for any help...
There's nothing in the API to do that. If you want to know when the other process has finished its work, create a manual reset event with CreateEventEx, and have the other process set the event when its work is done. The first process can use one of the wait functions to query the status of the event.
Acording to my understanding Dispatcher.Invoke and Dispatcher.BeginInvoke executes on UI thread, The only difference is That Invoke is synchronous and BeginInvoke is asynchronous.My problem is when i use this code
EDisc.App.Current.Dispatcher.
Invoke(
DispatcherPriority.Normal, new Action(delegate
{
context = NavigationManager.CurrentPage.DataContext;
}));
Value of context is returned. However with the below code
EDisc.App.Current.Dispatcher.
BeginInvoke(
DispatcherPriority.Normal, new Action(delegate
{
context = NavigationManager.CurrentPage.DataContext;
}));
Context is null and i get an InvalidOperation Exception saying "
The calling thread cannot access this object because a different thread owns it.I am calling this from a WCF service which is executing with UseSynchronizationContext = false .Can anybody explain this behaviour?
Both BeginInvoke and Invoke will end up calling an internal method called BeginInvokeImpl to do the work. The difference is that Invoke then waits for the operation to complete before returning.
And there's one other difference: if you are already on the UI thread and you're using DispatcherPriority.Send Invoke will actually invoke the method directly without going via BeginInvokeImpl, meaning that the operation is processed without going via the message queue. (If you're not using Send then any other messages already queued up with higher property than your operation will get processed first.)
But since you're presumably not on the UI thread here - you're on some WCF callback - that special case won't apply. So Invoke ends up calling into the same underlying implementation as BeginInvoke.
From the information you've provided, I'd have to guess that there's a missing detail somewhere here. The code you've shown should work fine, unless perhaps you have multiple UI threads in your application, and the page that happens to be in CurrentPage belongs to different threads from time to time.
If you do have multiple UI threads, then the approach you're using - pushing everything through the current Application object's dispatcher - isn't going to work, because you'll have multiple dispatchers. You'd need to get the right dispatcher for whichever UI element you're planning to touch.
Incidentally, one way you might accidentally end up with multiple UI threads is if you construct a UI object (e.g. a Page) on some worker thread or callback. Is it possible that you've done that somewhere?
I have a problem here and need your help. I've been trying to capture keyboard strokes from a created window using cvWaitKey() function. The function works fine if I called the cvWaitKey from the same thread that created the window, but when I create the window from a thread and call cvWaitKey() from another thread it doesn't return correct key, it blocks for cvWaitKey(0) and returns -1 for any timeout grater than zero.
Yes, this cannot work. cvWaitKey() is implemented by calling the PeekMessage() API function. That can only see messages on the message queue which is associated with the thread. The thread you created doesn't have any windows.
There is no obvious workaround for this, you have to call it on the thread that created the window. Calling GetAsyncKeyState() could work, a very different approach though.
In you "other" thread, you can set some shared variable to true or false (or some value), and make the "window thread" checks it before deciding whether to call cvWaitKey() in its local scope.
This is a question which follows on from my previously answered question here
At first I assumed I had a problem with the way I was creating my events due to the handles for OpenEvent returning NULL, I have managed to find the real cause however I am not sure how to go about it.
Basically I use Visual Studio to launch both Process A and B at the same time, in the past my OpenEvent handle wouldn't work due to Process A looking for the address of the event a fraction of a second before Process B had time to make it.
My solution was to simply allow Process B to run before Process A, fixing the error.
The problem I have now is that Process B now reads events from Process A and as you expect it too returns a null handle when trying to open the events from Process A.
I am creating the events in WM_CREATE message of both processes, furthermore I also create a thread at the same time to open/read/act upon the events.
It seems if I run them at the same time they don't get chance to see each other, alternatively if I run one before the other one of them misses out and can't open a Handle.
Can anyone suggest a solution?
Thanks.
Just replace OpenEvent with CreateEvent. CreateEvent will open an Event instead of creating a new one it finds an existing event with the name passed to CreateEvent.