|
You could simply call Form.Hide() instead of closing the forms outright..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
|
Let me first start with what I am trying to accomplish and what I have.
I created a computer management console for active directory. You launch, it gets all computer objects from AD. When you click the computer object, some panels become visible and thre are 3 listbviews. One for Installed Applications, One for Services, and one for Hard drive information. All of that information is retrieved by WMI.
So the way I have it is when you click a computer object, it attempts to contact the computer using seperate threads for each thing (applications, services, hd info).
I have something like this:
Thread m_workerThread1;
Thread m_workerThread2;
Thread m_workerThread3;
Semaphore resourceLock;
When you click comp:
if (m_workerThread1 != null && m_workerThread1.IsAlive)
m_workerThread1.Abort();
if (m_workerThread2 != null && m_workerThread2.IsAlive)
m_workerThread2.Abort();
if (m_workerThread3 != null && m_workerThread3.IsAlive)
m_workerThread3.Abort();
lstServices.BeginUpdate();
lstServices.Items.Clear();
m_workerThread1 = new Thread(new ParameterizedThreadStart(GetRunningServices));
m_workerThread1.IsBackground = true;
m_workerThread1.Start(comp.DnsHostName);
lstApplications.BeginUpdate();
lstApplications.Items.Clear();
m_workerThread2 = new Thread(new ParameterizedThreadStart(GetInstalledApps));
m_workerThread2.IsBackground = true;
m_workerThread2.Start(comp.DnsHostName);
lstDiskDrives.BeginUpdate();
lstDiskDrives.Items.Clear();
m_workerThread3 = new Thread(new ParameterizedThreadStart(GetCompInfo));
m_workerThread3.IsBackground = true;
m_workerThread3.Start(comp.DnsHostName);
And under each method (you see I am calling three different ones) I am using the resourceLock.WaitOne(); and under a try catch finally (in the finally) I am releasing it.
You might be wondering why I call abort. This is because I really couldn't think of a better way to abort the current operation if the user clicks another computer. Having it wait until its done before letting the user choose another computer really isn't an option (because WMI can take a while sometimes).
My problem is if you close the form while these threads are running. Right now I forgot to include anything for it and it causes teh app to crash.
Is there a good way to abort these and then close? Like without displaying a message for the user to wait and try again until it aborts? What is the "best practice" for handling something like this? Or did I just mess the whole system up the way I did it?
|
|
|
|
|
Looks like you are not clear about what a Semaphore does. I haven't got why you are using it here.
Jacob Dixon wrote: You might be wondering why I call abort. This is because I really couldn't think of a better way to abort the current operation if the user clicks another computer. Having it wait until its done before letting the user choose another computer really isn't an option (because WMI can take a while sometimes).
Whole point of using threads is to allow users to do things in parallel. This means that, user should be able to browse multiple computer details and each should open in it's on windows. So user don't have to wait until an operation finishes and you don't have to abort threads forcefully. Also, I don't see any reason to create new threads each time. Queuing the tasks into ThreadPool should be good enough. ThreadPool threads are background threads.
Jacob Dixon wrote: My problem is if you close the form while these threads are running. Right now I forgot to include anything for it and it causes teh app to crash.
A background thread should get aborted automatically when the main thread exits. Are you sure the main thread exits correctly? I guess the WaitOne call on Semaphore is blocking main thread and screwing up something.
Jacob Dixon wrote: What is the "best practice" for handling something like this?
IMO, allow users to view details of multiple computers. Clicking each computer will queue a job to the worker thread and open a new window (or tab?) to show the details. So user can view computer details while other requests gets processed in the background. Avoid calling Abort() , avoid creating your own threads instead use a ThreadPool . Also make sure your main thread is not blocked.
Best wishes,
Navaneeth
|
|
|
|
|
I created three threads and didn't want more than 3 running at one time. Thats why I used the semaphore. I haven't used a Threadpool before (new to threading as you might can tell lol). Let me read some on it and see what I can do with it.
Duh yeah opening in new windows would be more practical. Don't ask me why I didn't do that. I had a treeview on the left with the computers and on the right the listvies that displayed the info on the cmoputers. Im going to go with the new window suggestion lol.
|
|
|
|
|
I would try to use async WMI calls.
ManagementObjectSearcher query = new ManagementObjectSearcher(managementScope, new ObjectQuery(szSelectStatement));
ManagementOperationObserver observer = new ManagementOperationObserver();
observer.CompletedEventHandler += ;
ManagementObjectCollection queryCollection = query.Get(observer);
Now you should wait for 2 events in your threads. The first event signals that your
query is completed. And the second event should signal that the thread should cancel
the query (observer.Cancel() ).
Now you can sync your threads without having the need of abort them.Greetings
Covean
|
|
|
|
|
I have never had any luck with ManagementOperationObserver. I have posted on multiple forums (incluiding Microsoft) of why it fails.
If I'm correct you can use that for installing applications. Using it allows you to view detailed information about the install running (like what it is doing). I've only been able to get it to work on local machine and not when doing remote instaleld with WMI.
|
|
|
|
|
|
I never worked with remote WMI so I never ran in this problem.
So back to the topic.
I think in your case you can abort your threads.
But I think it would be a better solution, to tell the thread (you want to abort) that it should exit immediately after it finished its query and leave it alone/let it run till its exits (maybe you should add a kind of observer to abort threads, that didn't finish in a determined timeout).
So you couldn't use your semaphore any more (because of the possibility, that more than 3 threads are running) but it would be better to let the thread make a clean exit.
Why I think this is a better solution?
WMI calls are made through some unmanaged (not sure) COM interfaces.
Now if you abort your thread, there maybe will be some resources that would be still locked and never
gets freed till the application exits.
On the other hand you could also try to do some clean up in your thread if it gets aborted.
Something like this:
public void ThreadFunc(object obj)
{
try
{
DoSomeOperation();
}
catch(ThreadAbortException ex)
{
DoAbortCleanupStuff();
}
finally
{
}
}
I hope that helps.Greetings
Covean
|
|
|
|
|
I've been asked to write a script that runs on certain files across a server. These files are always stored within the same location within each top level folder e.g
Server\folder1\mydoc\file
Server\folder2\mydoc\file
Server\folder3\mydoc\file
Server\folder4\mydoc\file
So I have a script that runs on 'file'
I need this script or another program to monitor 'Server' finding all 'files' in that location to process and also to find 'file' whenever a new folder eg 'folder5' is created.
Is this even possible? I have no idea how to proceed or what to start reading up on to work out how to be able to do this.
Many Thanks
|
|
|
|
|
You could write a windows service that monitors the folders (with a FileSystemWatcher object), and fires off a processing thread whenever a new file is copied to one of the folders..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Great, I'll check it out. Many thanks
|
|
|
|
|
BTW, your message got me thinking about the FileSystemWatcher , and there a few gotchas you should be aware of. Some programs may cause the Changed event to fire twice for each file they create (Notepad is one of those programs). The problem with FileSystemWatcher is that you don't know why the file changed - just that it did. So I started messing around wit code and am in the middle of a wrapper class that addresses that issue. I hope to post an article about it before the end of the weekend..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I posted my article(s). It's a two-part series, and I think you might be interested, especially in Part 2.
FileSystemWatcher - Pure Chaos (Part 1 of 2)[^]
FileSystemWatcher - Pure Chaos (Part 2 of 2)[^].45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi All,
I have to out put the result of my INputfile.aspx file in to an Html file on a browser.
The code under my Inputfile.aspx file is as follow:
DataSet ds=new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("T2S_SELECT_SENDFINAL_msg", Utilities.ConnectionString);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
sda.Fill(ds);
DataTable dt=ds.Tables[0];
GVResult.DataSource = dt;
GVResult.DataBind();
The out put is just a single column from a table.
I would like the data to be seen on Inputfile.html not on Inputfile.aspx?
Is there any way i can convert my aspx file in to Html.So that the browser shows Inputfile.html not aspx?
Many thanks
|
|
|
|
|
You need to setup your web server to handle aspx. Once this is setup, it will be able to understand the content of your aspx files and output html files to the browser. You don't need to worry about this conversion.
|
|
|
|
|
Thanks for your help much appreciated.
I have only one html file in the project.All the remaining are *.aspx files.
Can you let me know what should i do on my webserver?
Many thanks
|
|
|
|
|
R u there?
please dont answer like the way you have mentioned.becuase it doesnt mean anything.
|
|
|
|
|
Sorry I am not good at explaining things. I had configured Microsoft IIS before, to handle ASP.NET applications. I also configured Apache to achieve the same thing. However, the details on how I did this cannot be explained here because I had forgotten all of them. However, the process is not complicated. The web servers have plug-ins to handle ASP.NET. You need to specify how aspx files are handled. Please refer to Microsoft documentations for more information. Other experts here may also give you a better answer. Please wait patiently!
Good luck!
|
|
|
|
|
Thanks so much for your help.
|
|
|
|
|
Hi;
How can i run the webcam on the my notebook in c# 2005. I read alot of paper in internet but i cant. i think need library then import my project but i cant. So there are any help somebody.
|
|
|
|
|
you can p/invoke the twain_32.dll (thats ofcourse requers that your webcam has twain compatible drivers), Or you can use WIA (see: WebCam Fast Image Capture Service using WIA[^]), the 3rd option is to use DirectX, 4th option (and probably the easiest), is to use a 3rd party .net component.
|
|
|
|
|
I use windows media encoder.
|
|
|
|
|
can you explain it please!
|
|
|
|
|
OK,
First you need to download the windows media encoder. I use version 9
http://www.microsoft.com/downloads/details.aspx?FamilyID=5691ba02-e496-465a-bba9-b2f1182cdf24&displaylang=en.
Once you download it and install, run it from the start menu. The dialogs are straight ahead.
You will be broadcasting a live event from your server. Pick your device from the device options menu. I use Broadcast Method = pull from...
Pick a port (I use 2009. URL for Internet = http://192.you.fil.lin:port# or choose a lan connection or both. I use multiple rates.
Once you have it working and you can see your broadcast at the server. Let me know and I can give direction on the ASP.net end of it.
|
|
|
|