How to make a console c++ app to run in the background?

Hello.
You need to remove the console window, and somehow make it so that the application is not completed after running the code.
Ie I have a few background threads that perform certain actions, but running all the threads from main, the app is terminated
int main(int argc, char *argv[])
{
 std::thread thr(SetView);
thr.detach();
 std::thread thr2(SetListen);
thr2.detach();
 return 0;
}

And if the threads do not background, then the operation does not go beyond the launch of the first stream (in the flow of infinite loops).
June 10th 19 at 14:37
2 answers
June 10th 19 at 14:39
Solution
To get rid of the console, the correct way to run application as a service in windows
https://code.msdn.microsoft.com/windowsapps/CppWin...
https://habrahabr.ru/post/71533/
or as a daemon in unix
https://stackoverflow.com/questions/17954432/creat...
A good example, however, the service does not install without admin rights, and my need for my software could open everywhere( - Christian.Thi commented on June 10th 19 at 14:42
On windows create an empty project
#include <windows.h>

int APIENTRY WinMain(
 HINSTANCE hInstance,
 HINSTANCE hprevinstance is,
 LPSTR lpCmdLine,
 int nCmdShow
)
{
//here the application logic
 return 0;
}</windows.h>

Then the app will be compiled as window, but as it will not set the window procedure, the application will just silently run in the background. - Marty93 commented on June 10th 19 at 14:45
But this method is rather hack than the rule. Don't do it. - Marty93 commented on June 10th 19 at 14:48
hmm, thank you so much, it's exactly what wanted to achieve.
Another would be the option to run multiple threads, in which actions are executed in a loop, and that the application is not ended after their launch.
If you do.detach();
then the application terminates immediately after starting the threads (well, they are at the same time with him). If you're doing
.join();
then the app wants to wait until the first thread (again, there are infinite loops), and doesn't want to run other.
(i.e., the goal is to start multiple threads with infinite loops in them in a row, and not close). - Christian.Thi commented on June 10th 19 at 14:51
To run flows from flow that Lee :D - Christian.Thi commented on June 10th 19 at 14:54
I have just picked up doc.qt.io/qt-5/qtconcurrent.html (option for the lazy)
API standard threads disgusting. - Marty93 commented on June 10th 19 at 14:57
June 10th 19 at 14:41
Need to wait for completion of threads.
int main(int argc, char *argv[])
{
 std::thread thr(SetView);
thr.detach();
 std::thread thr2(SetListen);
thr2.detach();
thr.Join();
thr2.Join();
 return 0;
}
Alas, sidefacing flows cannot connect) - Christian.Thi commented on June 10th 19 at 14:44

Find more questions by tags C++