树莓派单声道未触发事件 [英] 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远程访问它.
I have been following this post for developing a client for query notification. http://www.youdidwhatwithtsql.com/started-query-notifications-sql-server-2008-r2/1676/ I have tried this code on both visual studio and mono on my PC and these seem to fire the onDependencyChange event fine. However when I move it over to the raspberry pi with mono-complete installed it does not seem to fire. I cannot debug as the pi is in another location and I am using SSH to remote into it.
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,但是当我使用调试器运行时,它会起作用正如它应该.它将触发该事件.
I have now put an extra Console.WriteLine just under RefreshDataWithSqlDependency method and when I use Run > Run With > Microsoft .NET or Mono 4.0.2 it seems to jump straight out of RefreshDataWithSqlDependency, however when I run with debugger it acts as it should. It will fire the event.
推荐答案
远程调试将是使用SSH隧道的一种方式.
Remote debugging would be the way to go with SSH tunneling.
在Ras-pi端,启动您的应用程序:
On the Ras-pi side, start your app:
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是正确的)
(Yes, the address of 0.0.0.0 is correct)
在PC端,设置一个环境变量以启用Xamarian Studio/MonoDevelop的隐藏调试功能,并从该cmd行启动IDE.
On the PC side, set an environment variable to enable a hidden debug feature of Xamarian Studio / MonoDevelop and start the IDE from that cmd line.
在Linux上:
export MONODEVELOP_SDB_TEST=1
monodevelop
在OS-X上(如果使用Xam Studio,请更改cmd以使用MonoDevelop:
On OS-X (with Xam Studio, alter the cmd to use MonoDevelop if that is what you have:
export MONODEVELOP_SDB_TEST=1
/Applications/Xamarin\ Studio.app/Contents/MacOS/XamarinStudio
在Windows上(更新路径以匹配您的安装位置):
On Windows (update the path to match your install location):
set MONODEVELOP_SDB_TEST=1
<path>\XamarinStudio.exe
IDE启动后,加载要调试的解决方案/项目,设置断点,然后选择以下菜单项:
Once the IDE starts, load your solution/project that you are debugging, set your breakpoints and then select the following menu items:
Run / Run With / Custom Command Soft Mono Debugger
注意:如果您没有设置env var并从cmd行运行它,则该选项将不存在.
在出现的启动软调试器"窗口中:
In the Launch Soft Debugger Window that appeared:
Command : ssh YourRaspiLogin@RasPiPassword -L 10000:127.0.0.1:10000
Arguments : <leave empty>
IP : YourRasPiHostNameOrIPAddress
Port: : 10000
点击连接".
将打开一个ssh窗口,只需将其保持打开状态(将其最小化)即可,这就是您的反向隧道.如果您正在使用其他ssh客户端;油灰等.在命令字段中更改"ssh"以匹配您的设置.
A ssh window will open, just leave it open (minimize it..), that is your reverse tunnel. If you are using some other ssh client; putty, etc.. change the 'ssh' in the command field to match your setup.
您现在应该进行调试,并假设设置了断点,IDE应该在该行上停止等待您的;-)
You should be debugging now and assuming you set a break point the IDE should be stopped on that line waiting for you ;-)
这篇关于树莓派单声道未触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!