English 中文(简体)
非锁定的奥功能,而不是焚烧。
原标题:non-blocking io function instead of cin.get()

I have a c++ console application which has an option to be interrupted by pressing any key (implemented by using kbhit()) and in that case it prints what it has done and exits (or can be left to finish the work(some recording) and still prints feedback). I am making a c# gui application for that console application (I m calling exe file from c# form) and instead of pressing any key on the keyboard, I am using a "stop" button which sends Environment.NewLine (or " ") to the redirected input and in the c++ application I now have to use something different from kbhit() for it to work. I tried using cin.get(), like:

if (kbhit() || (cin.get() > 0))  
    stop_recording=true;  

但是,植被(植被)是一种阻挡功能,如果我希望奥果申请能够最终结束,那么它就在不要求停地纽托克的情况下获得了关闭。 是否有任何功能类似于实际上是阻塞性的植物,或者可能采取不同的方式将“任何关键”从c#到我的青ole应用过程?

问题回答

use _getch() insted of cin.get(). its a blocking command, but by executing it only if ( _kbhit() ) it will return immediately.

您可尝试发送。 Ctrl+C to the console process tostart itsbreak conduct.

如果你需要继续使用,即,在贵方倡议过程中,你可以检查点名的同声器(有随机名称),并将这一名称传给青少年进程。 如果青少年仍然能够获取Mustex/Semaphore,并且不再能够进入,则会同时检查一次。

@Komyg建议的其他选择是,如果特定投入显示,则将read光用于阅读 con和检查。

If you expect more communication between the programs search for IPC "inter-process communication" to see more approaches.

Found a very simple answer here: Simple example of threading in C++. Credits go to Edward Kmett.
I happened to use boost library in the c++ application so I could use boost threads implementation as well. It was quite simple, this is what my thread function look like:

bool stopped=false;

void inputSent() //
{  
    if (kbhit() || (cin.get() > 0))  
        stopped=true;  

}  

以及后来的主要文件:

boost::thread stoppedThread = boost::thread(inputSent);  

在那之后,我只检查了是否停止了=入侵,而我没有停止使用。 校对。 加入(我不知道这一错误是否错了,因为我不知道方案何时结束,如果我离开茨ombie深处......也许有人会让我了解这一点)。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签