c# - Do I need to worry about Process in foreach loop -
here piece of code, run through process , when finds right process, code sends message. question happened 'proc', how dispose process.
//get other (possible) running instances process[] processes = process.getprocesses(); foreach (process proc in processes) { if (proc.processname.tolower() == processname.tolower()) { sendmessage(proc.mainwindowhandle, (uint)message, intptr.zero, intptr.zero); } }
thanks in advance, harsha
in general terms don't need worry disposing or deallocating objects, unless object implements idisposable
interface. if should either call dispose()
method on manually when you're finished, or wrap using
statement have called automatically:
using (var disposableobject = new disposabletype()) { // work disposableobject }
Comments
Post a Comment