I have one scheduler which is running on Windows Service. For each new event it creates new thread. Each thread then load DLL using AddIn Framework and execute the task.
It is working fine but now but according to new requirement i want to be able to kill any event if we decide to do so or event is taking much time in execution.
Code for starting thread
ThreadStart ts = KickOffEvents;
Thread t = new Thread(ts);
So to do that i need to issue something so scheduler can understand and kill specific thread. But as that scheduler hosted on window service i am not able to do so.
Can anyone tell any work around in this???
Currently i am working on to move scheduling functionality to IIS by creating WCF service. Then i will be able to call function of wcf service which will in a way kill any event(thread).
Can anyone provide any input in whether any underlying risk in doing so???
Thanks in Advance
There is no way for the scheduler to explicitly kill the thread it has spawned. You will need to set a flag that the thread looks for and it will have to bring itself down. Anything else can result in undefined behavior
You can use a WCF service request to set this flag
Related
Suppose my WCF Service Application is "single-threaded" and I process some stuff on a background thread, but then need to service the processed data on the main IIS thread. (conversely, and seemingly more easily, I could lob all incoming methods to be re-called on the background thread, but this is not what I'm asking).
How can I, from the background thread, "notify" the main thread that my WCF methods are being invoked upon, to "wake up" and go process a method I specify?
I'm not super-familiar with the inner workings of WCF & IIS. I'm taking a guess that my service's methods are being called from completion ports and I should take as little time as possible in them, to prevent the IO servicing stuff from choking. I'm starting to think that if I want everything synchronized on one thread (calls to my methods, and my video-processing operations I need to perform), then I should make a command q and put all incoming method calls onto the command Q.
Surely this is an extremely common scenario. How do most people do this?
From my understanding, you are trying to run something in background, and process something else further based on the result from background job.
Maybe you can try the Task, which you can specify the callback (Task.ContinueWith) when the task is finished.
The GUI of my program freezes while the program is doing its work. I created a mass import which can send X-thousand datarows via a called webservice into a database. The code is already very big and I cannot rewrite it for multithreading purpose.
I don't know how to do it. Any suggestions? If needed I will show some code, but at the moment I don't know what to show.
Firstly, you should rewrite it to use avoid synchronously doing this on the UI thread. If you do a lot of work on the UI thread, it simply will freeze the UI thread. There are a few options here:
If your web service proxy supports asynchronous calls, and if you're using VB 11, you can use Async / Await to call the web service asynchronously from the UI thread in an asynchronous method, and control will return back to the UI thread at the same point in the asynchronous method when the call has completed. It takes a little while to get your head round asynchrony, but this is probably the best option if it's possible.
You can use the Task Parallel Library to make calls on a different thread, but then you'll need to think carefully about how that thread is going to interact with your UI thread.
You can use BackgroundWorker to run some code on another thread, but report progress and completion back on the UI thread
You could potentially call Application.DoEvents between each web service call, to let the UI handle events. This is dangerous - it can lead to re-entrant code, so locks won't behave as you expect them to, and similar hard-to-diagnose errors. This should be your last option, if all else fails.
I have a One way WCf Service which will just log entries in database.Normally it will run for 10 - 20 mins . Is there any way to cancel the service when any need arises ?
On button click i'l be triggering the one way WCF service . Now m planning to add cancel button which should stop currently triggered service. Could anyone help me in achieving this.
You can either make the operation IsOneWay, or implement the asynchronous pattern. To prevent threading issues, consider using the SynchronizationContext. Programming WCF Services does a great job at explaining these.
You can even consider using a BackgroundWorker.
Here is a nice Guide regarding Async and Sync calls:
http://www.codeproject.com/Articles/91528/How-to-Call-WCF-Services-Synchronously-and-Asynchr
I have an httpListener exe that is working great. What I need to do now is make it a service (I think) so that when the server is rebooted, this program will start automatically. I found a few tutorials for making services and I got one installed, but when I started it, it said it took to long to respond. I was thinking that might be because I have a while true loop going in the onStart method.
Anyone have any thoughts?
if the service onStart event just dives into business logic, the event never ends, so the service does not complete startup. I don't have a VB.NET example, but my approach has been to create a timer in IniializeComponent event, complete with a smallish interval and wire up of a timer.elapsed event.
The OnStart event then has one line of code in it to start the timer. The service startup completes, then the service starts getting to work when the Timer.Elapsed event fires.
It's impossible to answer this question directly without more information (e.g. on what exactly you're doing). However, that should not be necessary as you should be able to debug it yourself by attaching the debugger to the running service, as explained here.
I have to design and implement a way to deal with long running processes in a client/server application. A typical long running process would/could take 2-3 minutes. I also need to report progress to the UI in the meantime and keep the UI responsive.
Having these in my mind I though of a few solutions:
One async request to start the process which starts the server-side process and returns an assigned LRPID (Long Running Process ID) then poll periodically from the client using that LRPID. (Pro: simple to deploy, no firewall messing around Con: Unelegant, resource consuming etc.)
Use a duplex binding (such as NetTcpBinding) and initiate callbacks from the server as progress is being made (Pro: Elegant, efficient, Con: Deployment nightmare)
[Your suggestion???]
What would be your take on this?
Here is a post by Dan Wahlin about how to create a WCF Progress Indicator for a Silverlight Application. This should be of some help.
If you do not want to have to worry about the client's firewall, etc... I would probably go with your first solution and use a BackGroundWorker to make the call in order to keep from blocking the UI thread. I did this recently for an app where a request to generate a report is put on a queue and is retrieved once it is done. It seems to work well.
Another way (without having to change the WCF binding) is to use a WebBrowser control in the WPF client, and SignalR to post progress messages from the server to that control.
Note that to avoid javascript errors that happen with the WebBrowser control (because by default it seems to use Internet Explorer version 7 which doesn't seem to be compatible with jQuery.js), you will need to add keys to the registry on the client machine to change the default for the client app to use IE10 or later - see http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version).
This could be a deployment nuisance (because admin rights seem to be needed - eg on a 64 bit Windows 8.1 pc - to add the registry keys).
Also, it still seems necessary to call the long running WCF method in a separate thread, otherwise the WebBrowser control doesn't seem to update its display to show the SignalR messages it is receiving. (This makes sense because the UI thread would otherwise have to wait until the WCF call had finished).
But I mention it as an alternative approach using a newer tool (SignalR) :)