1

A quick background on the project... I'm running a web app that allows users to control and read data from devices connected to the server machine (in my case, an Intel NUC).

My issue is that I'm trying to detect global mouse events inside of a System.Windows.Form that's run in a background thread.

    private static Thread serviceThread;

    private IKeyboardMouseEvents mouseEvents;

    private int currentPixel = 0;
    private List<byte> rgb = new List<byte> { 255, 0, 0 };

    public static void StartService()
    {
        serviceThread?.Abort();
        serviceThread = new Thread(() =>
        {
            Application.Run(new TiltWheelService());
        });

        serviceThread.Start();
    }

    public TiltWheelService()
    {
        mouseEvents = Hook.GlobalEvents();
        mouseEvents.MouseDown += OnMouseDown;
        mouseEvents.MouseWheel += OnMouseScrollWheel;
    }

Now, when I run the app via IIS Express through Visual Studio 2017 (in either Debug or Release), it launches my App, brings up an instance of Chrome, and creates a windows form successfully, and I'm able to listen to any mouse event (in this case mouse down and scroll) and do what I want with it.

When I publish this to my locally running IIS Manager, however, the Windows Form never shows up and I'm unable to listen to mouse events.

Any suggestions would be helpful!

Brian Corbin
  • 267
  • 1
  • 12

1 Answers1

1

I don't think this is possible. When running your website under iisexpress in visual studio, it's running in an normal application as hosting environment. A normal application can show windows anytime, so there is no problem.

Opposed to this, iis (and therefore the asp.net worker process) is running as a service. Services are supposed to be run in the background, without any user interaction. Furthermore, to maintain the security of the server, the worker process runs under a restricted user account.

And finally, with default settings, worker processes are started when the first http request comes in and stopped after some idle time. In the meantime, all you mouse movements will be lost, because your web application simply isn't running.

I would propose that you try other solutions, which might be:

  • you get your mouse coordinates with the winforms programm and communicate them to the webserver (for example with a named pipe)
  • you access the external devices with some kind of api and not by mouse coordinates
  • you don't use a webserver for that job, use some remote terminal solution in combination with your winforms app

Some additional resources to read (there may be more):

Community
  • 1
  • 1
ventiseis
  • 3,029
  • 11
  • 32
  • 49
  • Thanks for the suggestions @ventiseis! I ended up going with a separate program running to capture the data and pipe it to my web app being hosted in IIS. Works like a charm, really, and is how I should have started this project, haha. – Brian Corbin Mar 11 '17 at 15:08