thx alot korvacs for this amazing link it helped alotQuote:
[Only registered and activated users can see links. Click Here To Register...]
thx alot korvacs for this amazing link it helped alotQuote:
[Only registered and activated users can see links. Click Here To Register...]
I appreciate the research you've done into that, but as long as it doesn't actively draw, it won't do much at all. Besides, the advantages of having a GUI overweight the costs.Quote:
You know why it's bad that you're using a GUI for this? Especially when it's Windows Forms, because it uses GDI+ which is VERY SLOW and it might slow down your performance over a longer period.
When it comes to software, GUI isn't as important as performance, you can see this when you go over a place in which systems are still coded in Cobol and alike, so I sincerely and respectfully hope that this statement I have quoted is not serious at all, no programmer will think like this, everQuote:
Besides, the advantages of having a GUI overweight the costs.
But you are drawing actively, because your console is not a console. It's drawing to your form which invalidates the whole form means every time you write something to it then your form and your "console" is redrawn. That's repeated every time your write something to your console and overtime it's going eat up your memory. It's not a lot, but it's enough considering it's a server then you should value performance over GUI.Quote:
I appreciate the research you've done into that, but as long as it doesn't actively draw, it won't do much at all. Besides, the advantages of having a GUI overweight the costs.
/// <summary>
/// Delegate usd to handle safe invoke events.
/// </summary>
public delegate void SafeEvent();
/// <summary>
/// A class to handle safe invokes on Windows Form Applications. It can be used to handle invokes on cross-threading problems as well it won't slow any threads down. It runs over its own thread.
/// </summary>
public class SafeInvoker
{
private static ConcurrentDictionary<int, SafeInvokeEvent> safeEvents;
private static SafeRandom safeRandom;
/// <summary>
/// Event invoked by the safe invoker.
/// </summary>
private class SafeInvokeEvent
{
public bool Invoked = false;
public SafeEvent Event;
public Control Ctrl;
}
static SafeInvoker()
{
safeEvents = new System.Collections.Concurrent.ConcurrentDictionary<int, SafeInvokeEvent>();
safeRandom = new SafeRandom();
new Thread(new ThreadStart(Safe_Thread)).Start();
}
/// <summary>
/// Invoking a control/form with an event.
/// </summary>
/// <param name="ctrl">The control/form to invoke.</param>
/// <param name="safeEvent">The event to invoke.</param>
public static void Invoke(Control ctrl, SafeEvent safeEvent)
{
SafeInvokeEvent siEvent = new SafeInvokeEvent();
siEvent.Event = safeEvent;
if (ctrl != null)
siEvent.Ctrl = ctrl;
int id = safeRandom.Next();
while (!safeEvents.TryAdd(id, siEvent))
id = safeRandom.Next();
}
private static void Safe_Thread()
{
while (true)
{
foreach (KeyValuePair<int, SafeInvokeEvent> sEvent in safeEvents)
{
if (!sEvent.Value.Invoked)
{
if (sEvent.Value.Ctrl != null)
{
if (sEvent.Value.Ctrl.InvokeRequired)
sEvent.Value.Ctrl.Invoke(new MethodInvoker(() =>
{
sEvent.Value.Event.Invoke();
}));
else
sEvent.Value.Event.Invoke();
}
else
sEvent.Value.Event.Invoke();
}
sEvent.Value.Invoked = true;
SafeInvokeEvent rEvent;
safeEvents.TryRemove(sEvent.Key, out rEvent);
}
Thread.Sleep(50);
}
}
}
SafeInvoker.Invoke(this,
() =>
{
label1.Text = rnd.Next().ToString();
label2.Text = rnd.Next().ToString();
label3.Text = rnd.Next().ToString();
richTextBox1.Text += rnd.Next().ToString();
richTextBox1.Text += "\n";
});