Event not firing on raspberry pi mono

徘徊边缘 提交于 2019-12-12 00:08:51

问题


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]);
            }
        }
    }

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.


回答1:


Remote debugging would be the way to go with SSH tunneling.

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

(Yes, the address of 0.0.0.0 is correct)

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.

On Linux:

export MONODEVELOP_SDB_TEST=1 
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

On Windows (update the path to match your install location):

set MONODEVELOP_SDB_TEST=1 
<path>\XamarinStudio.exe

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 

Note: That option will NOT be there if you you did not set the env var and run it from the cmd line.

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

Click "Connect".

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.

You should be debugging now and assuming you set a break point the IDE should be stopped on that line waiting for you ;-)



来源:https://stackoverflow.com/questions/31363926/event-not-firing-on-raspberry-pi-mono

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!