Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# windows service subscribed to webserver

I'm working on an intranet website. All users should get desktop popups from the webserver whenever something new is posted on the website.

I was looking to make my own windows service that would subscribe to the server ( Making use of something like SignalR ) and then this service would show a simple popup notifying the user whenever the server sends out a message.

But instead of building this myself i was wondering if something like this isn't already out there. I've been looking around a bit but couldn't find anything.

I'm mainly a web developer and have never built a windows service or C# desktop application so i would prefer using some existing code.

Does anyone know of such a thing ?

like image 904
Timon Avatar asked May 22 '15 08:05

Timon


2 Answers

For building a Windows Service try Top Shelf: http://docs.topshelf-project.com/en/latest/ In general it is easy as one, two, three...

public class TownCrier
{
    readonly Timer _timer;
    public TownCrier()
    {
        _timer = new Timer(1000) {AutoReset = true};
        _timer.Elapsed += (sender, eventArgs) => Console.WriteLine("It is {0} and all is well", DateTime.Now);
    }
    public void Start() { _timer.Start(); }
    public void Stop() { _timer.Stop(); }
}

public class Program
{
    public static void Main()
    {
        HostFactory.Run(x =>                            
        {
            x.Service<TownCrier>(s =>                   
            {
               s.ConstructUsing(name=> new TownCrier());
               s.WhenStarted(tc => tc.Start());         
               s.WhenStopped(tc => tc.Stop());          
            });
            x.RunAsLocalSystem();                       

            x.SetDescription("Sample Topshelf Host");   
            x.SetDisplayName("Stuff");                  
            x.SetServiceName("Stuff");                  
        });                                             
    }
}
like image 81
Marjan Nikolovski Avatar answered Oct 11 '22 05:10

Marjan Nikolovski


I'm working on an intranet website. All users should get desktop popups from the webserver whenever something new is posted on the website.

using timer is not a good technique over here as updates are not guaranteed in particular interval or session .but you can take that as an option based on the need.

I was looking to make my own windows service that would subscribe to the server ( Making use of something like SignalR ) and then this service would show a simple popup notifying the user whenever the server sends out a message.

Yes exactly like a chat application that would frequently have messages and users get a pop up.ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the ability to have server code push content to connected clients instantly as it becomes available, rather than having the server wait for a client to request new data.

enter image description here

But instead of building this myself i was wondering if something like this isn't already out there. I've been looking around a bit but couldn't find anything.

References for SignalR Link1,Link2,Link3

enter image description here

I'm mainly a web developer and have never built a windows service or C# desktop application so i would prefer using some existing code.

Making C# desktop or windows service is not a big deal as you already are a programmer.Some existing codes for updations pop up is here.

like image 29
Tharif Avatar answered Oct 11 '22 05:10

Tharif