Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将MSDN示例从C翻译为C++/CLI invokererequired) { //创建一个委托以执行线程切换。 OnChangeEventHandler^tempDelegate= gcnewonchangeventhandler(this,&Form1::dependency\u OnChange); cli::array^args=gcnew cli::array(2); args[0]=发送方; args[1]=e; //封送来自工作线程的数据 //到UI线程。 i->BeginInvoke(tempdegate,args); 回来 } //移除处理程序,因为它只是好的 //只需一次通知。 SqlDependency^dependency=safe\u cast(发送方); dependency->OnChange-=gcnewonchangeventhandler(this,&Form1::dependency\u OnChange); //此时,代码正在 //UI线程,因此更新UI是安全的。 ++变更计数; label1->Text=changeCount.ToString(); }_C#_C++ Cli_Code Translation - Fatal编程技术网

C# 将MSDN示例从C翻译为C++/CLI invokererequired) { //创建一个委托以执行线程切换。 OnChangeEventHandler^tempDelegate= gcnewonchangeventhandler(this,&Form1::dependency\u OnChange); cli::array^args=gcnew cli::array(2); args[0]=发送方; args[1]=e; //封送来自工作线程的数据 //到UI线程。 i->BeginInvoke(tempdegate,args); 回来 } //移除处理程序,因为它只是好的 //只需一次通知。 SqlDependency^dependency=safe\u cast(发送方); dependency->OnChange-=gcnewonchangeventhandler(this,&Form1::dependency\u OnChange); //此时,代码正在 //UI线程,因此更新UI是安全的。 ++变更计数; label1->Text=changeCount.ToString(); }

C# 将MSDN示例从C翻译为C++/CLI invokererequired) { //创建一个委托以执行线程切换。 OnChangeEventHandler^tempDelegate= gcnewonchangeventhandler(this,&Form1::dependency\u OnChange); cli::array^args=gcnew cli::array(2); args[0]=发送方; args[1]=e; //封送来自工作线程的数据 //到UI线程。 i->BeginInvoke(tempdegate,args); 回来 } //移除处理程序,因为它只是好的 //只需一次通知。 SqlDependency^dependency=safe\u cast(发送方); dependency->OnChange-=gcnewonchangeventhandler(this,&Form1::dependency\u OnChange); //此时,代码正在 //UI线程,因此更新UI是安全的。 ++变更计数; label1->Text=changeCount.ToString(); },c#,c++-cli,code-translation,C#,C++ Cli,Code Translation,编译C#示例源代码,然后使用将程序集反编译为MC++(托管C++) 编译C#示例源代码,然后使用将程序集反编译为MC++(托管C++) 以下是我的快速尝试: private void dependency_OnChange( System::Object^ sender, SqlNotificationEventArgs^ e) { // This event will occur on a thread pool thread. // Updating the UI fr

编译C#示例源代码,然后使用将程序集反编译为MC++(托管C++)

编译C#示例源代码,然后使用将程序集反编译为MC++(托管C++)

以下是我的快速尝试:

private void dependency_OnChange(
   System::Object^ sender, SqlNotificationEventArgs^ e)
{
    // This event will occur on a thread pool thread.
    // Updating the UI from a worker thread is not permitted.
    // The following code checks to see if it is safe to
    // update the UI.
    ISynchronizeInvoke^ i = this;

    // If InvokeRequired returns True, the code
    // is executing on a worker thread.
    if (i->InvokeRequired)
    {
        // Create a delegate to perform the thread switch.
        OnChangeEventHandler^ tempDelegate =
            gcnew OnChangeEventHandler(this, &Form1::dependency_OnChange);

        cli::array<System::Object^>^ args = gcnew cli::array<System::Object^>(2);
        args[0] = sender;
        args[1] = e;

        // Marshal the data from the worker thread
        // to the UI thread.
        i->BeginInvoke(tempDelegate, args);

        return;
    }

    // Remove the handler, since it is only good
    // for a single notification.
    SqlDependency^ dependency = safe_cast<SqlDependency^>(sender);

    dependency->OnChange -= gcnew OnChangeEventHandler(this, &Form1::dependency_OnChange);

    // At this point, the code is executing on the
    // UI thread, so it is safe to update the UI.
    ++changeCount;
    label1->Text = changeCount.ToString();

}
private void dependency\u OnChange(
系统::对象^sender,SqlNotificationEventArgs^e)
{
//此事件将发生在线程池线程上。
//不允许从工作线程更新UI。
//下面的代码将检查
//更新用户界面。
ISynchronizeInvoke ^i=此;
//如果InvokeRequired返回True,则代码
//正在工作线程上执行。
如果(i->invokererequired)
{
//创建一个委托以执行线程切换。
OnChangeEventHandler^tempDelegate=
gcnewonchangeventhandler(this,&Form1::dependency\u OnChange);
cli::array^args=gcnew cli::array(2);
args[0]=发送方;
args[1]=e;
//封送来自工作线程的数据
//到UI线程。
i->BeginInvoke(tempdegate,args);
回来
}
//移除处理程序,因为它只是好的
//只需一次通知。
SqlDependency^dependency=safe\u cast(发送方);
dependency->OnChange-=gcnewonchangeventhandler(this,&Form1::dependency\u OnChange);
//此时,代码正在
//UI线程,因此更新UI是安全的。
++变更计数;
label1->Text=changeCount.ToString();
}

以下是我的快速尝试:

private void dependency_OnChange(
   System::Object^ sender, SqlNotificationEventArgs^ e)
{
    // This event will occur on a thread pool thread.
    // Updating the UI from a worker thread is not permitted.
    // The following code checks to see if it is safe to
    // update the UI.
    ISynchronizeInvoke^ i = this;

    // If InvokeRequired returns True, the code
    // is executing on a worker thread.
    if (i->InvokeRequired)
    {
        // Create a delegate to perform the thread switch.
        OnChangeEventHandler^ tempDelegate =
            gcnew OnChangeEventHandler(this, &Form1::dependency_OnChange);

        cli::array<System::Object^>^ args = gcnew cli::array<System::Object^>(2);
        args[0] = sender;
        args[1] = e;

        // Marshal the data from the worker thread
        // to the UI thread.
        i->BeginInvoke(tempDelegate, args);

        return;
    }

    // Remove the handler, since it is only good
    // for a single notification.
    SqlDependency^ dependency = safe_cast<SqlDependency^>(sender);

    dependency->OnChange -= gcnew OnChangeEventHandler(this, &Form1::dependency_OnChange);

    // At this point, the code is executing on the
    // UI thread, so it is safe to update the UI.
    ++changeCount;
    label1->Text = changeCount.ToString();

}
private void dependency\u OnChange(
系统::对象^sender,SqlNotificationEventArgs^e)
{
//此事件将发生在线程池线程上。
//不允许从工作线程更新UI。
//下面的代码将检查
//更新用户界面。
ISynchronizeInvoke ^i=此;
//如果InvokeRequired返回True,则代码
//正在工作线程上执行。
如果(i->invokererequired)
{
//创建一个委托以执行线程切换。
OnChangeEventHandler^tempDelegate=
gcnewonchangeventhandler(this,&Form1::dependency\u OnChange);
cli::array^args=gcnew cli::array(2);
args[0]=发送方;
args[1]=e;
//封送来自工作线程的数据
//到UI线程。
i->BeginInvoke(tempdegate,args);
回来
}
//移除处理程序,因为它只是好的
//只需一次通知。
SqlDependency^dependency=safe\u cast(发送方);
dependency->OnChange-=gcnewonchangeventhandler(this,&Form1::dependency\u OnChange);
//此时,代码正在
//UI线程,因此更新UI是安全的。
++变更计数;
label1->Text=changeCount.ToString();
}

这是一段更大的代码的一部分;我不建议你把它全部贴出来,但它将不可能单独转换并让它有任何意义!纯C++还是C++?这将是不可使用的简单的C++,而不需要使用其他的库。你能提供一个链接,从你把这个代码集放到哪里,到C++ + CLI,这里是微软的原始链接为什么不只是在C++中编译它,引用C++ + CLI的程序集?这是一个更大的代码块的一部分;我不建议你把它全部贴出来,但它将不可能单独转换并让它有任何意义!纯C++还是C++?这将是不可使用的简单的C++,而不需要使用其他的库。你能提供一个链接,从你把这个代码集放到哪里,进入C++ + CLI,这里是微软的原始链接为什么不只是在C++中编译它,并从C++ +CLI?C++/CLI。忘记曾经存在过C++的托管扩展。C++/CLI。忘记曾经存在过C++的托管扩展。