我想在asp.net web中使用c#text.invoke函数 [英] i want to use c# text.invoke function in asp.net web

查看:515
本文介绍了我想在asp.net web中使用c#text.invoke函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii



i得到了奇怪的情况我将c#windows应用程序转换为基于aweb的应用程序,在代码中有一个名为 textbox.invoke的函数( )



用于多线程应用,据我了解



所以。 。在网上可以使用什么功能呢



 私人  void 日志(LogMsgType msgtype, string  msg)
{
rtfTerminal.Invoke( new EventHandler( delegate
{
rtfTerminal.SelectedText = string .Empty;
rtfTerminal.SelectionFont = new 字体(rtfTerminal.SelectionFont,FontStyle.Bold);
rtfTerminal .SelectionColor = LogMsgTypeColor [( int )msgtype];
rtfTerminal.AppendText(msg);
rtfTerminal.ScrollToCaret();
}));
}



rtfTerminal是一个文本框!

这是代码部分

thx

解决方案





ASP.NET控件不包含 Invoke 方法,因为Web表单与Windows Forms具有另一个线程关联,因此ASP.NET控件不提供 Invoke 方法。在您的Web表单中,您不需要使用 Invoke 方法或类似的方法。


正如解决方案1正确地告诉您,你不需要在ASP.NET中使用调用,但你的问题源于你甚至不知道如何以及为什么使用它 System.Windows.Forms ,所以你滥用它。请查看我过去的答案:

Control.Invoke( )与Control.BeginInvoke() [ ^ ],

Treeview扫描仪和MD5的问题 [ ^ ]。



在ASP.NET案例中,您只需删除冗余行:

  void 日志(LogMsgType msgtype, string  msg )
{
rtfTerminal.SelectedText = string .Empty;
rtfTerminal.SelectionFont = new 字体(rtfTerminal.SelectionFont,FontStyle.Bold);
rtfTerminal.SelectionColor = LogMsgTypeColor [( int )msgtype];
rtfTerminal.AppendText(msg);
rtfTerminal.ScrollToCaret();
}





但是,如果这真的是日志记录,那么这不是一个好的解决方案。您需要了解ASP.NET日志记录。



一个广泛使用的产品是Apache log4net。请参阅:

http://logging.apache.org/log4net/ [ ^ ]。



此CodeProject文章可能很有用:

log4net教程 [ ^ ]。



-SA


hii

i got astrange situation iam converting c# windows application to aweb based application , inside the code there is function called textbox.invoke()

its for multithreading application as i understand

so .. what function can used in web like it

private void Log(LogMsgType msgtype, string msg)
    {
      rtfTerminal.Invoke(new EventHandler(delegate
      {
        rtfTerminal.SelectedText = string.Empty;
        rtfTerminal.SelectionFont = new Font(rtfTerminal.SelectionFont, FontStyle.Bold);
        rtfTerminal.SelectionColor = LogMsgTypeColor[(int)msgtype];
        rtfTerminal.AppendText(msg);
        rtfTerminal.ScrollToCaret();
      }));
    }


rtfTerminal is a textbox !
this is the code part
thx

解决方案

Hi,

The ASP.NET controls doesn''t contain a Invoke method, because a web form has another thread affinity then Windows Forms, so ASP.NET controls don''t provide a Invoke method. In your web form, you don''t need to use a Invoke method or something similar.


As Solution 1 correctly tells you, you don''t need to use Invoke in ASP.NET, but your problem is stemmed from the fact that you did not even know how and why to use it even in System.Windows.Forms, so you abused it. Please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

In your ASP.NET case, you can simply remove redundant lines:

void Log(LogMsgType msgtype, string msg)
{
    rtfTerminal.SelectedText = string.Empty;
    rtfTerminal.SelectionFont = new Font(rtfTerminal.SelectionFont, FontStyle.Bold);
    rtfTerminal.SelectionColor = LogMsgTypeColor[(int)msgtype];
    rtfTerminal.AppendText(msg);
    rtfTerminal.ScrollToCaret();
}



But, if this is really the logging, it is not a good solution. You need to learn about ASP.NET logging.

One widely used product is Apache log4net. Please see:
http://logging.apache.org/log4net/[^].

This CodeProject article could be useful:
log4net Tutorial[^].

—SA


这篇关于我想在asp.net web中使用c#text.invoke函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆