[英]Event not firing on raspberry pi mono
我一直在关注此帖子,以开发用于查询通知的客户端。 http://www.youdidwhatwithtsql.com/started-query-notifications-sql-server-2008-r2/1676/我已经在Visual Studio和PC上的Mono上尝试了此代码,这些似乎可以触发onDependencyChange事件。 但是,当我将其移至安装了单完整版的树莓派时,它似乎没有启动。 我无法调试,因为pi在另一个位置,并且我正在使用SSH远程访问它。
static void Main(string[] args)
{
Console.WriteLine ("-----------------APPLICATION STARTED------------------");
var connection = new SqlConnection(connectionString);
SqlDependency.Start(connectionString);
RefreshDataWithSqlDependency();
Console.WriteLine ("Why is it here?");
//blocks thread so you can read message
Console.ReadLine();
SqlDependency.Stop(connectionString);
}
static void RefreshDataWithSqlDependency()
{
//remove existing dependency if necessary
if (dependency != null)
{
dependency.OnChange -= onDependencyChange;
dependency = null;
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command = new SqlCommand("SELECT ipAddress FROM dbo.dbDevices", connection);
//Create a dependency and associate it with command
dependency = new SqlDependency(command, null, 1);
//Subscribe to the SqlDependency event.
dependency.OnChange += new OnChangeEventHandler(onDependencyChange);
//Start dependency listener
SqlDependency.Start(connectionString);
//execute command and refresh data
RefreshData(command);
}
}
private static void onDependencyChange(Object o, SqlNotificationEventArgs args)
{
Console.WriteLine("ondep gets hit");
if ((args.Source.ToString() == "Data") || (args.Source.ToString() == "Timeout"))
{
Console.WriteLine("Refreshing data due to {0}", args.Source);
RefreshDataWithSqlDependency();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Data not refreshed due to unexpected SqlNotificationEventArgs: Source={0}, Info={1}, Type={2}", args.Source, args.Info, args.Type.ToString());
Console.ForegroundColor = ConsoleColor.Gray;
}
}
private static void RefreshData(SqlCommand command)
{
using (var reader = command.ExecuteReader())
{
Console.Clear();
while (reader.Read())
{
Console.WriteLine("ip = {0}", reader[0]);
}
}
}
现在,我在RefreshDataWithSqlDependency方法下面放了一个额外的Console.WriteLine,当我使用“运行”>“运行方式”> Microsoft .NET或Mono 4.0.2时,它似乎直接跳出了RefreshDataWithSqlDependency,但是当我使用调试器运行时,它应按预期运行。 它将触发该事件。
远程调试将是使用SSH隧道的方法。
在Ras-pi端,启动您的应用程序:
mono \
--debug \
--debugger-agent=transport=dt_socket,address=0.0.0.0:10000,suspend=y,server=y,keepalive=250 \
foodata.exe
(是的,地址0.0.0.0是正确的)
在PC端,设置一个环境变量以启用Xamarian Studio / MonoDevelop的隐藏调试功能,并从该cmd行启动IDE。
在Linux上:
export MONODEVELOP_SDB_TEST=1
monodevelop
在OS-X上(如果使用Xam Studio,请更改cmd以使用MonoDevelop):
export MONODEVELOP_SDB_TEST=1
/Applications/Xamarin\ Studio.app/Contents/MacOS/XamarinStudio
在Windows上(更新路径以匹配您的安装位置):
set MONODEVELOP_SDB_TEST=1
<path>\XamarinStudio.exe
IDE启动后,加载要调试的解决方案/项目,设置断点,然后选择以下菜单项:
Run / Run With / Custom Command Soft Mono Debugger
注意:如果您没有设置env var并从cmd行运行它,则该选项将不存在。
在出现的“启动软调试器”窗口中:
Command : ssh YourRaspiLogin@RasPiPassword -L 10000:127.0.0.1:10000
Arguments : <leave empty>
IP : YourRasPiHostNameOrIPAddress
Port: : 10000
点击“连接”。
将会打开一个ssh窗口,只需将其保持打开状态(将其最小化即可),这就是您的反向隧道。 如果您正在使用其他ssh客户端; 油灰等。在命令字段中更改“ ssh”以匹配您的设置。
您现在应该进行调试,并假设您设置了断点,IDE应该在该行上停止等待您的;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.