如何制作一个返回输出并阻塞直到输出可用的自定义函数?我在想类似的东西Console.ReadLine()
。像这样的东西:
var resp = Output(); //blocks until output is sent.
...
//returns a string once SendOutput is called and hands over the string.
public static string Output() { /* what goes here? */ }
//Is this function even needed? Can I just fire Output somehow?
private static string SendOutput(string msg) { /* what goes here? */ }
...
//Calls sendoutput with the string to send.
SendOutput(msg);
基本上,我正在制作一个在获取数据之前被阻塞的侦听器(就像调用 一样console.readline
),并且我需要内部代码来制作阻塞器。