Quick Search for:  in language:    
code,fragment,demonstrates,program,change,nec
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,011,557. lines
 Jobs: 115. postings

 How to support the site

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for Visual Basic.
AniViewer
By Jerrame Hertz on 6/30


Click here to see a screenshot of this code!Raw Packet Sniffer
By Coding Genius on 6/30

(Screen Shot)

Check the support of a record set
By Freebug on 6/30


B++ Builder - VB without runtimes
By Anthonius on 6/30


Mr Blonde - Chat Program
By Mr Blonde on 6/30


MSN Messenger Status Detector
By Ryan Cain on 6/30


MSN advanced
By alias1990 on 6/30


MSN Messenger advanced
By alias1990 on 6/30


Locate Database
By Erica Ziegler-Roberts on 6/30


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Changing priority

Print
Email
 

Submitted on: 4/28/1999
By: Steve Pepper 
Level: Not Given
User Rating: By 5 Users
Compatibility:VB 4.0 (32-bit), VB 5.0, VB 6.0

Users have accessed this code 10347 times.
 
 
     This code fragment demonstrates how you can get a program to change it's own priority. Sometimes it is necessary to change the priority of a process from the default. The example that prompted this code was a program I had to launch from a commercial scheduler always defaulted to idle priority. This caused the program to miss it's processing deadline. Increasing the priority to normal or high solved the problem.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: Changing priority
' Description:This code fragment demonst
'     rates how you can get a program to chang
'     e it's own priority.
Sometimes it is necessary To change the priority of a process from the default.
The example that prompted this code was a program I had To launch from a commercial scheduler always defaulted to idle priority. This caused the program to miss it's processing deadline. Increasing the priority to normal or high solved the problem.
' By: Steve Pepper
'
' Assumes:To run this code, add a form t
'     o a new project with a timer and a label
'     .
The priority will toggle between idle and high every two seconds.
Under NT4, you can use the task manager To see the base priority of this process changing.
'
' Side Effects:Changing the priority of 
'     your process to REALTIME_PRIORITY_CLASS 
'     is a bad idea in Visual Basic.
I have only tested this code under NT4 sp4 and VB5 but I think it should work under Windows9x
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=1683&lngWId;=1'for details.'**************************************

Sub ChangePriority(dwPriorityClass As Long)

Dim hProcess& Dim ret&, pid& pid = GetCurrentProcessId() ' get my proccess id ' get a handle to the process hProcess = OpenProcess(PROCESS_DUP_HANDLE, True, pid) If hProcess = 0 Then Err.Raise 2, "ChangePriority", "Unable To open the source process" Exit Sub End If
' change the priority ret = SetPriorityClass(hProcess, dwPriorityClass) ' Close the source process handle Call CloseHandle(hProcess) If ret = 0 Then Err.Raise 4, "ChangePriority", "Unable To close source handle" Exit Sub End If
End Sub
Private Sub Form_Load()
Timer1.Interval = 2000 Call Timer1_Timer End Sub
Private Sub Timer1_Timer()
Static Priority& If Priority = IDLE_PRIORITY_CLASS Then Priority = HIGH_PRIORITY_CLASS Label1.Caption = "HIGH priority" Else Label1.Caption = "IDLE priority" Priority = IDLE_PRIORITY_CLASS End If
Call ChangePriority(Priority) End Sub


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
5/2/1999 1:45:00 PM:Owen M
There is one program that can see if 
the priority has changed under Win 4x. 
It is Taskinfo98. You can download it 
at download.com(i think!)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/7/1999 9:17:00 PM:Andy M. Lopez
Thanks for the free source code, 
Thax's
I just want to learn more... :>
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/11/1999 1:16:00 PM:33
1
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/2/1999 9:20:00 PM:Chan
do u know how to close other 
application like MS Access or Ms word?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/20/1999 9:33:00 AM:D
This code shows how powerful VB is and 
how easy it is to write powerful code. 
Changing the priority of a process 
programatically is powerful stuff and 
you showed how easy it can be done in 
VB. Thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/5/2000 5:51:19 AM:Bunzi
Fantastic Source-Code. Very useful, 
especially for security-tools.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/14/2000 5:01:08 PM:Dan Messenger
So wot will happen if i change the 
priority for ALL the processes so that 
they are all at the lowest priority ??
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/5/2002 3:39:30 AM:Evil Monkey
sweet! 5 globes from me!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.