Reputation: 1820
I have an ASP.NET WebApi Self-hosted service, which does some work with an object called Transaction
. Also, I have a separate WinForms application, which serves me as a client to which I download Transaction
. It is possible, that client could be Web application on Android application (service shouldn't care about it).
Transaction
has a property named Status
, which changes from submitted -> inprogress -> done/error during the operation.
Currently, my client works like this:
SubmitTransaction(Transaction t);
while(t.Status==inprogress)
{
Thread.Sleep(1000);
t= GetTransactionStatus();
}
As you see, I have to "PING" my service every second to get an status update. I'm wondering, is there any way to "listen" to my service and return Status
, when it get's updated on service without loop and sleep? I'm using .NET 3.5
Please, feel free to ask more information, thanks in advance!
Upvotes: 1
Views: 1574
Reputation: 18958
What you are looking for is called push notification
There are many library and implementation. The most famous in .net is SignalIR
There you can find an exemple on how to use it in not-webcontext: http://mscodingblog.blogspot.it/2012/12/testing-signalr-in-wpf-console-and.html
Anyway they are quite complex to setup and if you think you will have only a few client to request about that transaction and you don't need realtime pushnotification for other aspect of your app I think it is easier/faster to just check for status any X seconds as you are doing.
PS Please use a Timer and not Thread.Sleep
Upvotes: 2