473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C# App: Detecting Process.Exited causes violation

4
I'm fairly new to .NET programming, so bear with me a bit.

The application I'm developing implements a 'toolbar' type pull-down window that lists the applications that have been launched by the user (through my GUI). My current issue is with the detection of one of those processes exiting. When the user closes the application, I need to remove the menu item from my pull-down.

In order to accomplish this, I declare an event handler:
p.Exited += new System.EventHandler(this.processExited);

This works, but when I run the application in debug mode, Visual Studio gives me an 'InvalidOperation' exception stating that cross-thread operation is not valid when I exit the other app. I thought this was the purpose of using the event. Am I missing something basic? Would make a difference if the handler method was static?

Thanks,
Mike
Oct 12 '07 #1
6 3519
Plater
7,872 Expert 4TB
If you look up the error on MSDN you see they offer some workarounds for that.
They have a background worker and a delegate that calls NeedsInvoke or something.
If you play around with that you might find something that removes the "Exception".
Oct 12 '07 #2
mspace
4
Thanks for the response - I was unable to find anything useful. I keep coming back to the thought that I shouldn't need a workaround...
A process wouldn't detect if itself had ended, so by the nature of this event, another process is going to react to it. Why would it be causing an exception? Has anyone else had experience using this event?

I noticed in the sample code on MSDN that they never explicitly declare an EventHandler. Is that oversight, or would that be by design?

Mike
Oct 12 '07 #3
Plater
7,872 Expert 4TB
I usually run into this error when I have multiple threads on my own application.
(I like to have a textbox on the main window that gets updates from the other threads and that throws the same exception)

Do you have anything like that? A System.Threading.Timer or System.Threading.Thread running that might be trying to talk to something?
Oct 12 '07 #4
mspace
4
I have a few other threads that run other forms (OSK type things), but they are not involved in this issue.
The basic function is that I launch a process from my main form, retain the handle and display the title in a pull-down menu, then try to remove the title from the pull-down when the process exits.

I tried a few other things - it appears to only complain when I access controls on my form. Is it possible that windows runs this event handler in a thread by itself?
Oct 12 '07 #5
Plater
7,872 Expert 4TB
If it did, that would explain it.

Its really only a best practices type exception.
It's letting you know that what you're doing isn't garunteed to happen in the correct order and might go in to re-entry ( in the middle of say appending text to a textbox, another thread start doing it and one overwrites the other)
Oct 12 '07 #6
mspace
4
OK - thanks again for your help. I guess I will just ignore the exception and get back to work...
Oct 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: A | last post by:
Hi all, This is sort of a newbie question. I have a method that creates a process which in turn installs MSDE. Basically, after I start the process I need to wait until it is complete and then...
8
by: Droopy | last post by:
Hi, I am working for a few month on a C# project (mixed dll for calling C++ legacy code with a C# wrapper). Since this morning, I can't start my application anymore ! I got a...
0
by: Eric Twietmeyer | last post by:
Hello, Am I mistaken in thinking that if I have a mc++ dll that I should be able to link against it (so long as it has exported symbols via declspec(dllexport)) in an unmanaged application? I...
2
by: Steve | last post by:
I have created a console app that simply prints out a message a couple times, then exits, here is the code: <code> for(int i = 0; i < 10; i++) { System.Threading.Thread.Sleep(500);...
16
by: Caroline | last post by:
I am building a web application to gather user information then launch a process to calculate results. The process is a 3rd Party executable. I cannot get the process to start. Is there a...
9
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame....
5
by: B. | last post by:
I know there is similar post few years back, but it didn't help solving my problem: We have a big project. Our legacy code is ported to VC++ 2005 recently. We have new feature written in C#.Net....
8
by: Lonifasiko | last post by:
Hi, Using Process class I asynchronously launch an executable (black box executable) file from my Windows application. I mean asynchronously because I've got an EventHandler for "Exited" event....
6
by: Ashutosh Bhawasinka | last post by:
Hi, I am starting a process and I need to monitor it (wait and check if its still responding). But, I it seems that the Process.HasExited or Process.Exited doesn't work. I just need to know...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.