|
I tried to use ProcessThread.ProcessorAffinity, but how do I get a ProcessThread object? In my thread I can get the current thread using Thread.CurrentThread property, but that will give me a Thread object. How do I move from that to a ProcessThread type?
|
|
|
|
|
The only way I've found so far is to use the Process.Threads property to get a ProcessThreadCollection of the threads. I can't find any decent way to figure out which ProcessThread is which Thread -- Thread has the Name property but not Id, and ProcessThread has Id but not Name.
One crazy way to figure it out might be by looking at the ProcessThread.StartTime property. The newer object would be the new thread that you created. It's absolutely horrible, but it might be a temporary solution if you're in a hurry. Maybe you can isolate it in a private function so that you can replace it easily in the future?
|
|
|
|
|
|
Hello,
Is it possible to find out how many methods are listening to a certain event? For example, can I find out if there are one or more methods listening to the DragDrop event of a control?
If I can't find out the exact number of methods listening to an event, can I somehow remove all listeners of that event at once?
Thanks for your help,
-Flack
|
|
|
|
|
Do you mean how many eventHandler like this.eventName+=your method ???
ByMindOnlyYouCanDoIt
|
|
|
|
|
Right. Lets say some event handlers were added to an event using +=. Is there a way to find out how many handlers in total subscribed to that event?
Or, after adding some event handlers using +=, is there a way to remove all of them at once (even if you dont know how many handlers are subscribed)?
-Flack
|
|
|
|
|
Yes I pasted such a method only a few days back, but for a delegate, which of cource an event is. Here we go (in the class that defines the vent, else it wont be accessible from within the compiler, use reflection otherwise).
int eventcount = SomeEvent.GetInvocationList().Length;
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
I'm trying to log some trace information, and the stack trace isn't giving me sufficient details, so i'm having to log some additional information in a custom Trace class.
I'm just looking for a way to find out what the method name and signature is of the one that is currently being executed by a thread.
Cheers
Cata
|
|
|
|
|
Have a look at:
System.Reflection.MethodInfo.GetCurrentMethod()
|
|
|
|
|
Ah yes!
I had a look at the Reflection name space, but i've never used it before so i didn't know what to look for.
I've got some ideas i want to try out with reflection, but it's waaaay down on my list of projects at the moment.
Cheers for that mate!
Cata
|
|
|
|
|
Hi,
Anyone knows how can I access a Windows process ?
i.e. Say I'd like to know when Microsoft Word is working or how much CPU is it using right now, or is my screen saver is on...
Thank you in advance,
Nir
|
|
|
|
|
Hi,
If you use the “System.Diagnostics” namespace you can find all the information you need.
Example:
Process [] localAll = Process.GetProcesses();
textBox1.Text = "Total number of processes: " + localAll.Length.ToString();
Process [] has a lot of nice information on what is going on in you operating system.
Hope this helped you a bit.
/ Magnus
|
|
|
|
|
If I load a bitmap and save it to a stream as a BMP and then converts the stream to an array of bytes I will get all my image data without any problems. But if I change the ImageFormat.Bmp to ImageFormat.Gif I will get an empty array of bytes! Help! -anyone?
MemoryStream ms = new MemoryStream();
Bitmap bm = new Bitmap(“test.bmp");
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] imagedata = new byte[ms.Length];
ms.Read(imagedata, 0, (int)ms.Length);
/ Magnus
|
|
|
|
|
Maybe you were lucky the first time with the bitmap
Try putting in a Flush() command after you've written the bitmap.
WM.
What about weapons of mass-construction?
|
|
|
|
|
Thanks for the quick respond, unfortunately it didn’t help much - sorry . I still have the same error with the array (imagedata) being empty. And it still work ok when I formatted it a .BMP instead of .Gif!
This is the code as is:
Bitmap bm = new Bitmap("image1.bmp");
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
ms.Flush();
Console.WriteLine(ms.Length);
// Convert from stream to byte[]
byte[] imagedata = new byte[ms.Length];
ms.Read(imagedata, 0, (int)ms.Length);
ms.Flush();
// Convert from byte[] into a stream again.
ms.Write(imagedata, 0, imagedata.Length);
Bitmap bm2 = new Bitmap(ms);
|
|
|
|
|
|
Hi,
Thanks!!! It works perfect, but I still can’t understand how it worked with the BMP-encoding and not with Gif. Sometimes we must just accept the strange thinks in life
/ Magnus
|
|
|
|
|
Hello,
Can anyone tell me how to prevent my program being killed by pressing "End Task" of task manager ? I have seen that when we try to kill some apps it tells that we cannot terminate it, because of "some" reason.
Thanks James
|
|
|
|
|
Basically, you can't prevent this.
There are various reasons for not being able to kill the process, like the process is running under a priviledged or system account, is a system service where Windows cannot work without it, there is a debugger attached to the process, ...
But in all these cases, you're application would not be running under these circumstances. I've "heard" of a couple people doing this, but noone has ever come up with any code examples demonstrating it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
If you want to do this for a security program of some sort, you can have the program called under the user Administrator, and leave the computer on with a user account that doesn't have administrative rights.
Another way, depending on what you're trying to do, might be to start the program as a Windows service, and again, use a user account that doesn't have access to the Services control panel.
|
|
|
|
|
Why are you telling me this? I didn't post the question.
Also, I can't quite understand what your saying in the first paragraph, but it doesn't sound like a good idea. You NEVER use the Administrators account for anything other than system administration. Applications/Services/Servers should NEVER use this account.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Oops, sorry. Does a notification get sent to the original poster, or just to you?
And you're right, Administrator isn't the rght place to do it. How about a user specifically for the task, like what ASP does?
My bad on both the post and the idea.
|
|
|
|
|
Only the person you reply to gets a notification email.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm really curious what you want this for.
|
|
|
|
|
Hi!
In my program I'm using a class, which can nested like the TreeNodes in a
TreeView, thus I also want to use a TreeView to display some of the content
(a short string) of these nested classes. The user shall then be able to take
further actions when by clicking on the TreeNodes. Here comes the problem:
How do I map the currently selected TreeNode to the appropriate instance of
the nested class?
|
|
|
|