473,466 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why the currrent process has exited?

I have used the following method to set the running priority for a
process and its affiliated threads. It is noticable at statement (*)
that if the process has already exited, the method will return
immediately without further operations. However, sometimes the method
may generate the following exception:

================================================== =========
03/07/04 3:48:06 AM auto_rep.Run() error:
System.InvalidOperationException: The request can not be processed
because the thread (2428) has exited.
at System.Diagnostics.ProcessManager.OpenThread(Int32 threadId, Int32
access)
at System.Diagnostics.ProcessThread.OpenThreadHandle( Int32 access)
at System.Diagnostics.ProcessThread.set_PriorityBoost Enabled(Boolean
value)
at lib.libs.set_proc_priority(Process proc, Int32 level)
at DBSample.auto_rep.Run()
================================================== =========

The contextual codes calling the method are:

================================================== =========
if( libs.work_hour() )
libs.set_proc_priority( Process.GetCurrentProcess(), 1 );
else
libs.set_proc_priority( Process.GetCurrentProcess(), 2 );
================================================== =========

The full codes of the method are listed as below:

================================================== ========
public static void set_proc_priority( Process proc, int level )
{
int k;

if( proc.HasExited ) (*)
return;
proc.PriorityBoostEnabled = true;
switch( level )
{
case( -2 ):
proc.PriorityClass = ProcessPriorityClass.Idle;
for( k = 0; k < proc.Threads.Count; k++ )
{
proc.Threads[k].PriorityBoostEnabled = true;
proc.Threads[k].PriorityLevel = ThreadPriorityLevel.Idle;
}
break;
case( -1 ):
proc.PriorityClass = ProcessPriorityClass.BelowNormal;
for( k = 0; k < proc.Threads.Count; k++ )
{
proc.Threads[k].PriorityBoostEnabled = true;
proc.Threads[k].PriorityLevel = ThreadPriorityLevel.BelowNormal;
}
break;
case( 0 ):
proc.PriorityClass = ProcessPriorityClass.Normal;
for( k = 0; k < proc.Threads.Count; k++ )
{
proc.Threads[k].PriorityBoostEnabled = true;
proc.Threads[k].PriorityLevel = ThreadPriorityLevel.Normal;
}
break;
case( 1 ):
proc.PriorityClass = ProcessPriorityClass.AboveNormal;
for( k = 0; k < proc.Threads.Count; k++ )
{
proc.Threads[k].PriorityBoostEnabled = true;
proc.Threads[k].PriorityLevel = ThreadPriorityLevel.AboveNormal;
}
break;
case( 2 ):
proc.PriorityClass = ProcessPriorityClass.High;
for( k = 0; k < proc.Threads.Count; k++ )
{
proc.Threads[k].PriorityBoostEnabled = true;
proc.Threads[k].PriorityLevel = ThreadPriorityLevel.Highest;
}
break;
case( 3 ):
proc.PriorityClass = ProcessPriorityClass.RealTime;
for( k = 0; k < proc.Threads.Count; k++ )
{
proc.Threads[k].PriorityBoostEnabled = true;
proc.Threads[k].PriorityLevel = ThreadPriorityLevel.TimeCritical;
}
break;
}
return;
}
================================================== ========
Any solution to the problem?
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
0 1330

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

Similar topics

0
by: Dan McGuffin | last post by:
I am trying to develop some vb.net code that will will store 1 or more processes in an array of processes, then loop through the array determining when each one has exited. Upon each one exiting, I...
2
by: T | last post by:
How do you catch the "Exited" event when a process is terminated. In the following code sample the "myProcess_Exited" event is never called. Any help would be appreciated. using System; using...
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...
4
by: Peter | last post by:
I am using CreateProcessWithLogonW to run an external application, the problem I am having is that the C# program does not wait until the external program finishes running before continuing. The...
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...
7
by: Bob | last post by:
Process.start("Mydoc.doc") starts Word with the file. I need to wait for Word to be closed before more code can execute in my app. How can I do this? Thanks for any help Bob
3
by: jan.loucka | last post by:
Hi, Is there any way in .NET how to capture WIN API messages that belong to different application? We have a Windows Form app written in .NET 2.0 and from our application we're running another...
9
by: kimiraikkonen | last post by:
Hello, I want to automate something and display a simple msgbox that indicates my external process finished processing and "exited". My code is that, what things should i add more: Dim psInfo...
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: 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
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...
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,...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.