Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

C#
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
Posted
Comments
Sergey Alexandrovich Kryukov 24-Dec-12 13:03pm    
Why?! Do you know what Invoke is for? It's only for threading.
—SA

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.
 
Share this answer
 
Comments
promarkoo 24-Dec-12 9:25am    
how i can append text and send and recieve text without reloading page and without invoking !
Thomas Daniels 24-Dec-12 9:28am    
Sergey Alexandrovich Kryukov 24-Dec-12 13:15pm    
I answered in some details about logging, please see Solution 2.
—SA
Sergey Alexandrovich Kryukov 24-Dec-12 13:03pm    
Of course, a 5. And threading (Invoke is only needed for threading), is somewhat foreign topic with ASP.NET.
—SA
Thomas Daniels 25-Dec-12 4:01am    
Thank you!
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:
C#
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
 
Share this answer
 
Comments
__TR__ 24-Dec-12 14:00pm    
+5
Sergey Alexandrovich Kryukov 24-Dec-12 14:06pm    
Thank you,
—SA
__TR__ 24-Dec-12 14:12pm    
I just noticed something that's not related to this post.
This [^] person is in number 2 spot for Top Experts in 24hrs, but has not answered a single question in last 2 days. something is not right. What do you think?
Sergey Alexandrovich Kryukov 24-Dec-12 14:48pm    
I don't know. These top lists really looked weird to me during last days. Will you rather report it to
http://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspx?
—SA
__TR__ 24-Dec-12 15:17pm    
Just posted it in site Bugs/suggestion forum. The list keeps refreshing regularly, so by the time someone looks at that post this person may not be listed in the Top expert in 24 hrs list. Lets hope if there is a bug it gets fixed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900