|
Hi,
I am using something like this to get all my running processes:
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist)
{
Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id);
}
My problem is that I want to know the filename (EXE) of a process, and the pathname it was started from. For example, if there is a process Notepad.exe running, I want to determine in which folder that file actually resides, i.e. something like "C:\Windows\system32\notepad.exe". How can I get that information?
I already tried to get the member StartInfo. but it doesn't contain a link to the folder.
How can I do this?
|
|
|
|
|
Message Closed
modified 23-Nov-14 5:45am.
|
|
|
|
|
qwertz321 wrote: theprocess.MainModule.FileName
Good one
My vote 5.
|
|
|
|
|
You can also use
theprocess.Modules[indexno].FileName
|
|
|
|
|
that is much more expensive and in no way any better than what qwertz already provided.
|
|
|
|
|
Luc Pattyn wrote: that is much more expensive and in no way any better than what qwertz already provided.
Yes, that's why I vote 5 for qwertz and during writing my answer I have mention you can also use and code works very well. I just try to give an alternate answer.
|
|
|
|
|
Good its just look like a fire A complete + Answer
|
|
|
|
|
ShilpaKumari wrote: Good its just look like a fire A complete + Answer
Not a Matter
some people Down vote or comment without testing code, which is not good in any corner.
|
|
|
|
|
RaviRanjankr wrote: some people Down vote or comment without testing code, which is not good in any corner.
agree with you
|
|
|
|
|
RaviRanjankr wrote: theprocess.Modules[indexno].FileName
We need to handle Exception in this case.
|
|
|
|
|
MDNadeemAkhter wrote: We need to handle Exception in this case.
Yes, in both cases either you are using MainModules or Modules you need to handle exception..
|
|
|
|
|
Hi,
I have two datagridview, one is invisible. When i click the first datagridview then the other will visible, and i need to select a value from that grid. How can i drag rows in the new grid when i press down arrow?
Thankyou
|
|
|
|
|
Have a Look
http://www.codeproject.com/KB/webforms/DragAndDropGridView.aspx
http://www.telerik.com/community/forums/aspnet/grid/drag-and-drop-grid-rows.aspx
http://jqueryui.com/demos/sortable/#connect-lists
http://forums.silverlight.net/forums/p/164753/372597.aspx
http://themechanicalbride.blogspot.com/2009/08/new-with-silverlight-toolkit-drag-and.html
http://aspdotnetcodebook.blogspot.com/2009/04/how-to-move-selected-record-from-one.html
|
|
|
|
|
Hi,
I have a .NET C# application that contains many different assemblies. My start up project contains all assemblies as references, so when I build the application all these assemblies are copied to output directory.
Is it possible to replace one of the assemblies at runtime, if it exist a new version of that assembly?
Best regards
Olof
|
|
|
|
|
Short answer: No
Shortish answer: If you get to it early enough (before any types (or types that reference the types) are instantiated that reference the dlls) you can overwrite them.
Long answer: If you need more than the above gives you like being able to swap the types after they have been used you need to create a seperate AppDomain and load the dlls into that. If they get updated you can destroy the AppDomain and create a new one with the new dlls.
It all depends on what you are trying to achieve.
|
|
|
|
|
One way would be to load the assemblies using Reflection. That way, if an assembly changes periodically, you will get the latest
|
|
|
|
|
Hi, a lot of the types declared in the assembly I want to update at runtime are used both in this assembly and in other assemblies. And since a lot of people are working in the project at the same time it's not easy to make a bigger reorganization of the source files.
|
|
|
|
|
The traditional way to approach this would be to use Dependency Injection to inject the appropriate DLL at runtime. The best way to do this is to not hardcode your type references, but rather you would work against interfaces which the concrete classes would implement. There are many benefits to doing this such as creating more testable objects, improving the loose cohesion of the system, etc.
|
|
|
|
|
Hi,
I am currently writing a gui-application, which does some processing in a thread. I pass a reference to my mainwindow to the thread, in order to make the thread set some text inside the mainwindow. However, when I try to access any control in my mainwindow from my thread, I get:
"An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll"
Simple question: what is the best way to access mainwindo-gui elements from a thread?
This is what my code looks like:
public MainWindow()
{
InitializeComponent();
_ProcessHelperThread = new System.Threading.Thread(ProcessHelperThread);
_ProcessHelperThread.Start();
}
void ProcessHelperThread()
{
Processes.Init(this);
Processes.Startup();
}
Inside the thread (i.e. in my Processes-object), my app crashes when I try something like this:
public int Init(MainWindow window)
{
window.textBlock1.Text = Waittext;
}
What is a better way to do this?
|
|
|
|
|
I would have expected a cross thread exception rather than the one you got but the correct way to update gui elements from another thread is the call Invoke on the control. This is for WinForms not WPF.
public Form1()
{
InitializeComponent();
Thread workerThread = new Thread(WorkerThread);
workerThread.Start();
}
private void WorkerThread()
{
UpdateWindowText(this);
}
private void UpdateWindowText(Form1 form)
{
form.Invoke((Action) (() => form.Text = "test"));
}
|
|
|
|
|
As a follow up this is how it is done in WPF.
public MainWindow()
{
InitializeComponent();
Thread workerThread = new Thread(WorkerThread);
workerThread.Start();
}
private void WorkerThread()
{
UpdateWindowText(this);
}
private void UpdateWindowText(Window window)
{
window.Dispatcher.Invoke((Action) (() => window.Title = "test"));
}
|
|
|
|
|
Thanks alot, this solution works perfectly!
|
|
|
|
|
hi,
How to add a blank row in the last index when click on the datagridview. When we type any character in any cell a new blank row is generated by default, likewise i need to generate in any click. AllowUsertoaddrow is set to true.
Thankyou
|
|
|
|
|
This will create a new row when the current new row gets clicked. I could see how this may be annoying for users though but I will assume you have your reasons.
public Form1()
{
InitializeComponent();
dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView dataGridView = sender as DataGridView;
if(dataGridView.Rows[e.RowIndex].IsNewRow)
{
int newRowIndex = dataGridView.Rows.Add();
dataGridView.CurrentCell = dataGridView.Rows[newRowIndex].Cells[e.ColumnIndex];
}
}
|
|
|
|
|
I have a Server, and several Client.
a meth receive data from client. then store these data in global variable temporary then deal.
e.g.
public void ReceiveMethod(object data)
{
//maybe Multiple client at the same time.
DealData(data);
}
public void DealData(object data)
{
//some values will store in global variable temporary.
//because Multiple client Send data,so the global variable's value is mistake. like mult-Thread without synchrony or lock.
//if this is Multiple Thread deal, I understand it.
//but I dont execute thread or asynchronization obvious.
//is Mult-Thread here?
}
|
|
|
|