|
If your going to 1 vote atleast explain why, and how the post could be improved.
|
|
|
|
|
Use WMI. Try the following:
string cpuInfo = String.Empty;
string temp = String.Empty;
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == String.Empty)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
}
Console.WriteLine(cpuInfo);
Console.ReadLine();
Don't forget to include the System.Management Namespace.
Mustafa Ismail
There are 10 kinds of people in this world. Those who understand binary and those who don't...
______________________
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
|
|
|
|
|
Hi,
that is a complex question, and I don't have the complete answer.
What do you call a processor (there is some disagreement):
- there is hyperthreading (basically 2 or more processor states sharing all other
processor resources: functional units, caches, bus interface, ...), which you
can disable through BIOS
- there is multi-processing on a chip
- there is multi-chip packages
- and finally visible multi-processing: more than one IC package
And obviously these can be combined.
That's the technical view. Then there is the matter of software licensing,
which exists in many forms, such as per processor, per system, per seat.
There is room for debate!
Environment.ProcessorCount "Gets the number of processors on the current machine"
whatever that means. I expect/hope it to mean the largest number you can obtain
taking into account all the forementioned possibilities.
Also Process.ProcessorAffinity should have the value 2^n - 1 when
n=Environment.ProcessorCount
Hope this helps
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
That does help, quite alot! Combined with the other replies, I'm all set. Thanks!
-Gatsby
|
|
|
|
|
System.Environment.ProcessorCount will give you number of them (actually in some cases will return number of cores not processors just like DeviceManager!)
but if you need to know how many processors are on the machine really you can use WMI to found out
and it would be somewhat like this
static int ProcessorCount()
{
ManagementObjectSearcher mos = new ManagementObjectSearcher(new SelectQuery("Win32_Processor"));
ManagementObjectCollection moc = mos.Get();
List<string> processorIds = new List<string>();
foreach (ManagementObject mo in moc)
{
string pID = mo.Properties["ProcessorId"].Value as string;
if (!processorIds.Contains(pID))
processorIds.Add(pID);
}
return processorIds.Count;
}
in the code, processorIds were checked and because the cores from the same processor have identical processorIds they're not gonna be counted twice or more
hope the post would be useful
good luck
|
|
|
|
|
Quite helpful! Problem solved. Thank you.
-Gatsby
|
|
|
|
|
Hi,
I am trying to convert a Delphi project to c# project. As part of the project a C-dll is called to conduct simulation (pipe network analysis).
On some of the forms I have placed ZedGraph control. I am able to create these forms immediately before conducting simulation (i.e., before calling unmanaged C dll). However, immediately after simulation (i.e., after calling unmanaged C dll function), I am not able to create these forms. When I try to create these forms the application is abruptly getting terminated. I tried to locate the problem, and found that termination is occuring inside InitializeComponents() function (in particular, it is occuring when trying to initialize zedGraph control). All other forms (which do not contain ZedGraph) are working fine. I am not able to pinpoint the error. Anyone outhere could you please help me in correcting the mistake.
I should point out that the C-dll is working perfectly well as I can see the simulation reasults. However I do not know whether it is corrupting any memory. I can email the source code if anyone is willng to investigate it. I cannot post it here because it is a relatively large project. It will be made available as a freeware very soon.
Thanks in advance.
Regards,
Prasad
|
|
|
|
|
Prasad, you're not likely to get an answer to your question, and here's why:
1. No meaningful subject line, unlikely to attract people to see your question.
2. No specific question; e.g. you just describe an error and say you'll email someone with the source code.
3. Usage of specialized software: you're encountering a problem with the ZedGraph control. We don't know what this is. Perhaps this question is better suited to the support staff for that software.
|
|
|
|
|
I have a wide dropdown combobox on a form. I would like to move the button that activates the dropdown list from the right to the left side of the
combobox. I am aware of the RTL property but it also right aligns the text.
Does anyone have a soultion to this problem?
Thanks
James Johnson
|
|
|
|
|
Sorry James, can't be done. I work in a part of the world where RTL is the norm. Short of building your own combobox, there is no ready solution.
There are 10 kinds of people in this world. Those who understand binary and those who don't...
______________________
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
|
|
|
|
|
error Unable to attach to application 'Web.Dev.WebServer.Exe'(PID: 5860). using 'T-PC' which is the name for my SQL Server 2005 running on my machine. A debugger is already attached.
What does this mean??
I am trying to upload an Excel file to my SQL Server 2005 which is running on my machine.
|
|
|
|
|
Hi all,
I have a project that consist of several applications (Windows Services and WPF applications communicating via WCF). All applications need certain configuration information, that should be stored in a central / common file.
One application should also be able to write to this config file and the other apps should automatically notice these changes and read in the new values.
Now I'm looking for a way to realize that. I tried a FileSystemWatcher on a "normal" xml file (not a .Net configuation file) in connection with a Mutex to ensure that no application tries to read the file while another application is writing.
It didn't work (The Mutex seemed to be useless, I always got an exception that told me that the file could not be opened because it is already opened by another process).
Any ideas how I could implement this stuff? Should I stay by my "normal" xml file or should I switch to an .Net configuration based approach?
thanks and regards,
MMartin
|
|
|
|
|
The issue you have is that only one application can have the file open, at a time. So, the file watcher isn't going to work. You'd need instead to do something like have a timer which checks the last update time of a file, and have the code written in such a way that it anticipates the possibility of more than one program trying to read the file at once.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Christian,
thanks for your reply!
"The issue you have is that only one application can have the file open, at a time."
That's what I thought, too, and therefore I added a Mutex.
Loading the config file:
<br />
Core.Tracer.Info( "LoadConfigFile: Waiting for Mutex: " + i.ToString() );<br />
m_Mutex.WaitOne();<br />
Core.Tracer.Info( "LoadConfigFile: Locking Mutex: " + i.ToString() );<br />
m_Document.Load( ConfigFileName );<br />
m_Mutex.ReleaseMutex();<br />
Core.Tracer.Info( "LoadConfigFile: Releasing Mutex: " + i.ToString() );<br />
Writing the config file:
<br />
Core.Tracer.Info( "SaveConfigFile: Waiting for Mutex: " + i.ToString() );<br />
m_Mutex.WaitOne();<br />
Core.Tracer.Info( "SaveConfigFile: Locking Mutex: " + i.ToString() );<br />
if(m_Watcher != null) m_Watcher.EnableRaisingEvents = false;
m_Document.Save( ConfigFileName );<br />
if ( m_Watcher != null ) m_Watcher.EnableRaisingEvents = true;<br />
m_Mutex.ReleaseMutex();<br />
Core.Tracer.Info( "SaveConfigFile: Releasing Mutex: " + i.ToString() );<br />
But the Mutex is not working. In my log files I see something like this:
Application 1 Log:
20.08.2007 07:43:20.730; Agent:; LoadConfigFile: Waiting for Mutex: 1
20.08.2007 07:43:20.730; Agent:; LoadConfigFile: Locking Mutex: 1
20.08.2007 07:43:20.733; Agent:; something happend in LoadConfigFile: The process cannot access the file 'C:\Map\Map.config' because it is being used by another process.
Application 2 Log:
20.08.2007 07:43:20.724; Admin:; SaveConfigFile: Waiting for Mutex: 1
20.08.2007 07:43:20.726; Admin:; SaveConfigFile: Locking Mutex: 1
20.08.2007 07:43:20.752; Admin:; SaveConfigFile: Releasing Mutex: 1
I'm losing my mind?
How can Application 1 lock the Mutex at 07:43:20.730 when it is already locked by application 2 at 07:43:20.726?
Could it be that Mutex doesn't work in Windows Services?
Thanks,
MMartin
|
|
|
|
|
Aha,
it seems that the Mutex is not unique:
<br />
bool isNew = false;<br />
m_Mutex = new Mutex( false, "Map_ConfigFile_Mutex", out isNew );<br />
if ( isNew )<br />
{<br />
Core.Tracer.Info( "Mutex is new in System" );<br />
}<br />
else<br />
{<br />
Core.Tracer.Info( "Mutex is NOT new in System" );<br />
}<br />
Application 1 (Windows Service) log:
20.08.2007 08:09:40.672; Agent:; Mutex is new in System
Application 2 (WPF application) log:
20.08.2007 08:09:33.775; Admin:; Mutex is new in System
I ensured that it is not a life-time problem. The Mutex object exists as long as the application (which created the Mutex) exists. So: How can a Mutex be created by two different processes.
Does it make a difference that one application is a Windows Service?
I noticed that, if Application 1 (Windows Service) creates the Mutex, all other Windows Services will say:
20.08.2007 08:09:41.712; Coordinator:; Mutex is NOT new in System
very confusing...
MMartin
|
|
|
|
|
|
hi
I have a major problem.I am designing a simple simulator for my college project,in this simulator I may have some code running simultanesly (vitrual).I mean, in this simulator ,simulator engine may wait on an object and run another object an then return back to the original object like what we have in calling Methods.In this way parallel programming and multi threading in the Apllication layer comes possible.
I need to know if I can do this by halting execution in some point of the code manulay and run another code and the return back to the original code.This simulator runs on a single thread and may have many objects in it and can not have one thread per each object in order to use Mutex.
Thanks
|
|
|
|
|
Hi!
In my program I have to change the language of user's input programmaticaly. User of course is able to do it by himself using CTRL+SHIFT or whatever. But I have to make it by myself. Is there any property that will allow me to do it?
|
|
|
|
|
|
you can use System.Windows.Forms.InputLanguage Class to do this
Installed Languages can be retrieved through InstalledInputLaguages property
changing and retrieving current input language can be done through CurrentInputLanguage property
here is an example to change the input language to Farsi
<code>
foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
if(lang.LayoutName == "Farsi")
{
InputLanguage.CurrentInputLanguage = lang;
break;
}
</code>
and another way to change the language is through using cultures like
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(CultureInfo.CurrentCulture);
good luck
|
|
|
|
|
|
oops. Sorry. I just realized that I need this change in Console, not in Windows.Forms.
|
|
|
|
|
hello
I want to introduce you a tool in c# . with this tool you can connect to telnet.this is terminalemulator.
|
|
|
|
|
Hello,
I'm trying to work out a way to replace some text using regular expressions, but seems to be missing something. Here goes:
--------
inputstring = "<b>Str</b>: Large<br><b>Color</b>: Black<br>".
output should be: "Large-Black"
OR
inputstring = "<b>Str</b>: Small<br>"
output should be: "Small"
OR
inputstring = "<b>Str</b>: Large<br><b>Color</b>: Black<br><b>Engraving</b>: yes<br>"
output should be: "Large-Black-yes";
my regularexpression method looks like this:
{
string s = Regex.Replace(attribut, @"(<b>.*</b>)+:\s(?<keeper>.*)<br>", "${keeper}-");
return s.Remove(s.Length-1, 1);
}
But this will only give me the last ocourance of <keeper>. Eg Black for the first example given.
Any clue/help is very appreciated.
thanks
Frank
|
|
|
|
|
Have you checked your regex? Look for Expresso on this site. It is a wonderful tool for testing your regular expressions.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|