adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
531 stars 128 forks source link

How to call a process by button asynchronously ? #150

Closed sathanu closed 6 years ago

sathanu commented 6 years ago

I have created a small screen with start and stop button by minigui. It looks good. I want to start a service(*.exe) by the button click. When i do this, the screen comes to not responding. Is there any async library you have in the collection ? How to call exe asynchronously ?

adamdruppe commented 6 years ago

On Tue, Apr 10, 2018 at 09:53:30AM +0000, Sathanu wrote:

I have created a small screen with start and stop button by minigui. I want to start a service(*.exe) by the button click. When i do this, the screen comes to not responding. Is there any async library you have in the collection ? How to call exe asynchronously ?

Do you need to process output from that exe or just run it in the background without caring what it prints?

sathanu commented 6 years ago

just run it in the background without caring what it prints.

adamdruppe commented 6 years ago

In that case, Phobos' spawnProcess or spawnShell functions should do what you need. http://dpldocs.info/experimental-docs/std.process.spawnProcess.1.html

lemme know if that works for you. I do have a couple other options, but if this function works it is simpler.

sathanu commented 6 years ago

It is not working. The *.exe is vibe.d application. Can we start the vibe.d application in the click event of button ?

adamdruppe commented 6 years ago

On Tue, Apr 10, 2018 at 06:16:44PM +0000, Sathanu wrote:

It is not working. The *.exe is vibe.d application. Can we start the vibe.d application in the click event of button ?

It shouldn't matter what the exe is. What are you seeing when you try to run it? Does it throw an exception, or block on the call or what?

sathanu commented 6 years ago

The service is started. but the screen is not responding.

adamdruppe commented 6 years ago

On Tue, Apr 10, 2018 at 11:21:48AM -0700, Sathanu wrote:

The service is started. but the screen is not responding.

OK, what's the code you run in the button's click handler?

sathanu commented 6 years ago

void hello(HTTPServerRequest req, HTTPServerResponse res) { res.writeBody("Hello, World!"); }

auto router = new URLRouter; router.get("/hello", &hello); auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["::1", "127.0.0.1"]; listenHTTP(settings, router); runApplication();

adamdruppe commented 6 years ago

Well, that's the code in the exe, but I mean in your minigui code.

sathanu commented 6 years ago

If we make the below code work in minigui button click, No need to call the exe. It will reduce the difficulty. Is this possible ?

void hello(HTTPServerRequest req, HTTPServerResponse res) { res.writeBody("Hello, World!"); }

auto router = new URLRouter; router.get("/hello", &hello); auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["::1", "127.0.0.1"]; listenHTTP(settings, router); runApplication();

adamdruppe commented 6 years ago

On Tue, Apr 10, 2018 at 09:51:46PM -0700, Sathanu wrote:

If we make the below code work in minigui button click, No need to call the exe. It will reduce the difficulty. Is this possible ?

put it in a new thread. I'm not sure if vibe will love that, but that's how I'd start.

so the main thread then is your gui, and vibe lives in a worker thread that the gui can start and stop.

sathanu commented 6 years ago

Thanks. It is working now.

adamdruppe commented 6 years ago

Sweet!