<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dapfor.Net Grid Blog &#187; .net</title>
	<atom:link href="http://www.blog.dapfor.com/tag/net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.blog.dapfor.com</link>
	<description>.Net Grid and MFC Grid</description>
	<lastBuildDate>Fri, 09 Sep 2016 05:40:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>.NetGrid v2.9.4 has been released.</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-9-4-has-been-released-2</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-9-4-has-been-released-2#comments</comments>
		<pubDate>Sun, 03 Nov 2013 20:37:49 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=237</guid>
		<description><![CDATA[A new grid version containing minor error fixes has been released. The following bugs have been fixed: [BUG] Fix for the grid&#8217;s verbosity in the console of the VS IDE while painting. &#160; &#160;]]></description>
			<content:encoded><![CDATA[<p>A new grid version containing minor error fixes has been released.</p>
<p>The following bugs have been fixed:</p>
<ul>
<li>[BUG] Fix for the grid&#8217;s verbosity in the console of the VS IDE while painting.</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-9-4-has-been-released-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NetGrid v2.9.2 has been released.</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-9-2-has-been-released</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-9-2-has-been-released#comments</comments>
		<pubDate>Mon, 05 Aug 2013 17:24:42 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.Net Grid features]]></category>
		<category><![CDATA[INotifyPropertyChanged]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=227</guid>
		<description><![CDATA[A significant increase in productivity when working with objects that implement the INotifyPropertyChanged interface The following bug has been fixed: [BUG] Fixed a bug where the grid redraw the content of the entire row upon receiving notification from INotifyPropertyChanged interface for missing or hidden column. [BUG] Fixed minor bugs in the designer.]]></description>
			<content:encoded><![CDATA[<p>A significant increase in productivity when working with objects that implement the <a href="http://msdn2.microsoft.com/es-es/library/ms133020" target="_blank">INotifyPropertyChanged</a> interface</p>
<p>The following bug has been fixed:</p>
<ul>
<li>[BUG] Fixed a bug where the grid redraw the content of the entire row upon receiving notification from <a href="http://msdn2.microsoft.com/es-es/library/ms133020" target="_blank">INotifyPropertyChanged</a> interface for missing or hidden column.</li>
<li>[BUG] Fixed minor bugs in the designer.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-9-2-has-been-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NetGrid v2.9.0 has been released. New features and bug fixes</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-9-0-has-been-released-new-features-and-bug-fixes</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-9-0-has-been-released-new-features-and-bug-fixes#comments</comments>
		<pubDate>Wed, 05 Jun 2013 20:19:51 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.Net Grid features]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=215</guid>
		<description><![CDATA[We are glad to introduce a new grid version with improved performance and stability. We have added dozens new tests to cover various grid functions. We want to thank our customers for their feedback on products and ease of use and critical comments that help us make our products best on the market. The following [...]]]></description>
			<content:encoded><![CDATA[<p>We are glad to introduce a new grid version with improved performance and stability. We have added dozens new tests to cover various grid functions. We want to thank our customers for their feedback on products and ease of use and critical comments that help us make our products best on the market.</p>
<p>The following features have been added:</p>
<ul>
<li>[NEW] Added column filter serialization</li>
<li>[NEW] Reengineered grid designer introducing intuitive and convenient user interface.</li>
<li>[NEW] Significantly improved grid performance with selection large data volumes.</li>
<li>[NEW] Overall performance improvement.</li>
</ul>
<p>The following bugs have been fixed:</p>
<ul>
<li>[BUG] Fixed an error with the grid not unsubscribing from objects with composite properties when objects are removed from the grid.</li>
<li>[BUG] Fixed an error with Dapfor.Net.dll not appearing in the list of available assemblies in Visual Studio.</li>
<li>[BUG] Fixed an error with Column.Appearance property hiding cell highlighting.</li>
<li>Minor bug fixes</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-9-0-has-been-released-new-features-and-bug-fixes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NetGrid v2.8.5 has been released. New features and bug fixes</title>
		<link>http://www.blog.dapfor.com/netgrid-v2-8-5-has-been-released-new-features-and-bug-fixes</link>
		<comments>http://www.blog.dapfor.com/netgrid-v2-8-5-has-been-released-new-features-and-bug-fixes#comments</comments>
		<pubDate>Tue, 18 Dec 2012 22:45:40 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[basket viewer]]></category>
		<category><![CDATA[bug fixing]]></category>
		<category><![CDATA[new release]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.Net Grid features]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[threading]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=205</guid>
		<description><![CDATA[The new version includes several bug fixes and new features added to Dapfor’s framework. The following features have been added: [NEW] added new DecimalFormat and a corresponding DecimalFormatAttribute for declarative formatting. public class Product { private decimal price; [DecimalFormat(Precision = 3, ShortForm = true, ShowZero = false)] public decimal Price { get { return price; [...]]]></description>
			<content:encoded><![CDATA[<div id="sectionSectionID0EVAAA">The new version includes several bug fixes and new features added to Dapfor’s framework. The following features have been added:</div>
<div id="sectionSectionID0EVAAA">
<ul>
<li>[NEW] added new <a href="http://doc.dapfor.com/net-suite/html/T_Dapfor_Net_Formats_DecimalFormat.htm">DecimalFormat</a> and a corresponding <a href="http://doc.dapfor.com/net-suite/html/T_Dapfor_Net_Formats_DecimalFormatAttribute.htm">DecimalFormatAttribute</a> for declarative formatting.
<div>
<pre>public class Product
{
    private decimal price;

    [DecimalFormat(Precision = 3, ShortForm = true, ShowZero = false)]
    public decimal Price
    {
        get { return price; }
    }
}</pre>
</div>
</li>
<li>[NEW] Added new <a href="http://doc.dapfor.com/net-suite/html/E_Dapfor_Net_Ui_Grid_FocusedColumnChanged.htm">Grid.FocusedColumnChanged</a> event.</li>
<li>[NEW] Added a section for <a href="http://www.dapfor.com/en/net-suite/net-grid/tutorial/appearance">grid painting system</a>.</li>
<li>[NEW] Added a section for <a href="http://www.dapfor.com/en/net-suite/net-grid/tutorial/cell-highlighting">cell highlighting system</a>.</li>
<li>[NEW] Added a new example that demonstrates design of <a href="http://www.dapfor.com/en/net-suite/net-grid/tutorial/basket-viewer">Backet component</a> that is used for measuring weight of financial instruments in the basket. Contains detailed explanation of main principles of developing high-performance application with intensive computing operations. Describes specifis of painting system in Windows OS.</li>
</ul>
<p>The following bugs have been fixed:</p>
<ul>
<li>[BUG] The standard editor drop-downs do not appear on the correct monitor, if the main monitor is the right monitor, and the editor is being hosted on a monitor to the left of it.</li>
<li>[BUG] The grid didn’t start editing data if nullable types existed.</li>
<li>[BUG] If <a href="http://doc.dapfor.com/net-suite/html/P_Dapfor_Net_Ui_Grid_DataObjects.htm">Grid.DataObjects</a> were used, the grid didn’t clear collection on calling <a href="http://doc.dapfor.com/net-suite/html/M_Dapfor_Net_Ui_RowCollection_Clear.htm">Grid.Rows.Clear()</a> method.</li>
<li>[BUG] Change of focused columns was displayed incorrectly in <strong>FocusMode.Cell</strong> focusing mode.</li>
<li>[BUG] The grid was hiding some rows when binding data in grid with existing grouping.</li>
<li>Minor bug fixes</li>
</ul>
<p>&nbsp;</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/netgrid-v2-8-5-has-been-released-new-features-and-bug-fixes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Application.DoEvents() in real-time applications is dangerous!</title>
		<link>http://www.blog.dapfor.com/using-application-doevents-in-real-time-applications-is-dangerous</link>
		<comments>http://www.blog.dapfor.com/using-application-doevents-in-real-time-applications-is-dangerous#comments</comments>
		<pubDate>Tue, 06 Nov 2012 11:03:57 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[DoEvents]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=192</guid>
		<description><![CDATA[It has been numerously written that Application.DoEvents() method is not desirable, especially for high-performance applications. There are many reasons for this starting from message processing procedure and ending with non-evident problems with application response  to user activity and code execution. In most cases programmers use this method without thinking of consequences or its working principle. [...]]]></description>
			<content:encoded><![CDATA[<p>It has been numerously written that<strong> Application.DoEvents()</strong> method is not desirable, especially for high-performance applications. There are many reasons for this starting from message processing procedure and ending with non-evident problems with application response  to user activity and code execution.</p>
<p>In most cases programmers use this method without thinking of consequences or its working principle. <a href="http://msdn.microsoft.com/en-us//library/system.windows.forms.application.doevents.aspx">MSDN documentation</a> says that this method processes messages in queue and when there are no more messages it stops working and passes control to the next code.<br />
In simplified form this method looks as follows:<br />
<code><br />
NativeUnsafeMethods.MSG msg;<br />
while (PeekMessage(out msg))<br />
{<br />
TranslateMessage(ref msg);<br />
DispatchMessage(ref msg);<br />
}</code></p>
<p>However, we may wonder what happens when application is intensively rendering controls, synchronizing threads and performing other operations in GUI thread? In such situation message queue always contains messages that don’t let method finish its work. As the result, the end user won’t notice the difference in application behavior as<strong> Application.DoEvents()</strong> will process executing messages, including WM_PAINT messages, i.e. controls will be redrawn and the program will not slow down. However, code execution will stop on <strong>Application.DoEvents()</strong> method. If there are important operations after this method, they will not be executed until message queue is freed. We have often seen the situation when application was updating stock market prices and in times of high volatility prices were updated with noticeable delays!!!</p>
<p>A simple example of the problem is shown below. Demo application intensively synchronizes threads and paints data. Main GUI thread continuously processes messages (including synchronization messages and WM_PAINT messages). Clicking Start button calls Application.DoEvents() once, and in normal situation it should immediately return control to subsequent code. However, in this example the things are different! This method is followed by MessageBox.Show(…) that doesn’t display anything.<br />
If demo application is fully covered with any other window or collapsed in the taskbar, Windows stops sending WM_PAINT messages and as the result of it message queue becomes empty, <strong>Application.DoEvents()</strong> method stops and MessageBox.Show(…) is executed.</p>
<p><a href="http://www.blog.dapfor.com/using-application-doevents-in-real-time-applications-is-dangerous/doevents" rel="attachment wp-att-194"><img class="size-full wp-image-194 alignleft" title="DoEvents" src="http://www.blog.dapfor.com/wp-content/uploads/2012/11/DoEvents.png" alt="" width="505" height="311" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Download <a href="http://dapfor.com/downloads/net-suite-examples/DoEventsExample.zip">DoEventsExample.zip</a></p>
<p>Therefore, before using <strong>Application.DoEvents()</strong> programmers should look at application architecture and ask themselves whether this method is really necessary. If application code really requires <strong>Application.DoEvents()</strong>, we have added <strong>Dapfor.Net.Editors.MessageQueueHelper</strong> class starting from version 2.8.4. This class has similar behavior but it also supports maximum execution time limit. If there are no more messages in queue, <strong>MessageQueueHelper</strong> also stops and passes control to the subsequent code.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/using-application-doevents-in-real-time-applications-is-dangerous/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Correct organization of event processing in a separate thread</title>
		<link>http://www.blog.dapfor.com/correct-organization-of-event-processing-in-a-separate-thread</link>
		<comments>http://www.blog.dapfor.com/correct-organization-of-event-processing-in-a-separate-thread#comments</comments>
		<pubDate>Mon, 26 Dec 2011 10:35:56 +0000</pubDate>
		<dc:creator>dapadm</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[threading]]></category>
		<category><![CDATA[threadpool]]></category>

		<guid isPermaLink="false">http://www.blog.dapfor.com/?p=33</guid>
		<description><![CDATA[Multithreaded application became something common. The main reason for that is execution of resource-intensive tasks in parallel to GUI without stopping it for long operations. As it is well known, the easiest way for asynchronous data processing used by ThreadPool. This method is not only the easiest, but also very efficient. Notwithstanding its merits, it [...]]]></description>
			<content:encoded><![CDATA[<p>Multithreaded application became something common. The main reason for that is execution of resource-intensive tasks in parallel to GUI without stopping it for long operations. As it is well known, the easiest way for asynchronous data processing used by ThreadPool. This method is not only the easiest, but also very efficient. Notwithstanding its merits, it has one large backdraw – an application cannot manage ThreadPool lifetime and cannot be confident that during termination ThreadPool doesn’t process previously assigned tasks that may cause application crash.</p>
<p>Let’s review a specific case of threadpool implementation consisting of a single thread. The requirements to this implementation are:</p>
<ul>
<li>Delay between adding task to threadPool and initiation of its execution should be minimal</li>
<li>If there are no tasks, threadpool should not consume resources. Specifically, context switches should not be allocated to thread that doesn’t process tasks</li>
<li>Threadpool should provide an interface (IDisposable is the best for it) for correct work termination and guarantee that upon Dispose() call, all tasks including tasks in execution shall be completely terminated.</li>
<li>Tasks should be executed in sequence without acquiring synchronizing objects.</li>
<li>Enable recursive task execution</li>
<li>Providing interface for exception handling.</li>
</ul>
<p>So, there are many requirements and all of those are sufficient. Monitor class is most convenient to implement thread synchronizations. It allows to protect task queue and to move thread to sleep state where it doesn’t consume resources and take it out of this state upon receiving a signal. On adding a new task to the queue and on thread termination request a signal should be sent to this thread. Another useful property of the Monitor is recursive and safe acquiring of the same synchronizing object enabling recursive task addition.</p>
<p>Now let’s review the process of thread pool termination. When a new thread is launched, it is transmitted a method called by the newly created thread. This method usually contains a task processing loop. During execution this cycle constantly checks value of a flag that specifies whether it is necessary to stop task processing. This flag is initially set to false, but Dispose function is set to true. When the calling thread sets this flag to true and notifies the threadpool about it, this thread should wait until threadPool execution ends using Join() method. If threadpool execution doesn’t end in allocated time, the calling thread may be forcibly terminated using Abort().</p>
<p>Exception handling. All task exceptions occur in threadPool thread. Therefore, if it they are not processed, the thread stops. To prevent it, the thread should catch all exceptions occurring during task execution. In a well designed system threadpool should provide interface for notification of extraordinary situation. UnhandledException event is most suitable for this purpose.<br />
As new thread is not launched instantly, to prevent sending tasks to uninitialized thread, it is reasonable to add Monitor to thread start at threadPool.</p>
<p>Now we have just a few things to do – define the interfaces:</p>
<pre>public interface ITask
{
    void Execute();
}

public interface IDispatcher
{
    void Dispatch(ITask task);
}</pre>
<p>&nbsp;</p>
<p>An example of ITask implementation enabling use of anonymous methods and lambda expressions for code reduction:</p>
<pre>public class Task : ITask
{
    private readonly Action _action;

    public Task(Action action)
    {
        if (action == null)
        {
            throw new ArgumentNullException("action");
        }
        _action = action;
    }
    public void Execute()
    {
        _action();
    }
}</pre>
<p>Now comes the hero: a code implementing threadpool based on a single thread:</p>
<pre>internal sealed class SingleThreadDispatcher : IDispatcher, IDisposable
{
    private readonly Thread _thread;
    private bool _stopping;
    private readonly Queue _queue = new Queue();
    private readonly object _startSynchro = new object();

    public SingleThreadDispatcher()
    {
        lock (_startSynchro)
        {
            _thread = new Thread(Run) { IsBackground = true };
            _thread.Start();

            //White until the thread is started
            Monitor.Wait(_startSynchro);
        }
    }

    private void Run()
    {
        //Release the calling thread
        lock (_startSynchro)
        {
            Monitor.Pulse(_startSynchro);
        }

        while(true)
        {
            bool exit;
            ITask task = null;
            lock (_queue)
            {
                if (_queue.Count == 0)
                {
                    Monitor.Wait(_queue, 500);
                }
                else
                {
                    task = _queue.Dequeue();
                }

                exit = _stopping &amp;&amp; _queue.Count == 0;
            }

            //Execute task without lock
            if (task != null)
            {
                try
                {
                    task.Execute();
                }
                catch (Exception e)
                {
                    if(UnhandledException != null)
                    {
                        UnhandledException(this, new UnhandledExceptionEventArgs(e, false));
                    }
                }
            }

            if(exit)
            {
                break;
            }
        }
    }

    public void Dispatch(ITask task)
    {
        lock (_queue)
        {
            _queue.Enqueue(task);
            Monitor.Pulse(_queue);
        }
    }

    public void Dispose()
    {
        lock (_queue)
        {
            _stopping = true;
            Monitor.Pulse(_queue);
        }

        //Join for a thread and if it doesn't exits, abort it.
        if(!_thread.Join(2000))
        {
            _thread.Abort();
        }
    }

    public event UnhandledExceptionEventHandler UnhandledException;
}</pre>
<p>&nbsp;</p>
<p>Example of initialization:</p>
<pre>[STAThread]
static void Main()
{
    using (var t = new SingleThreadDispatcher())
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MyForm());
    }
}</pre>
<p>&nbsp;</p>
<p>Example of use:</p>
<pre>t.Dispatch(new Task(()=&gt;
{
    //Some code here
}));</pre>
<p>&nbsp;</p>
<p>Hope this will help you in your dev.<br />
Kind regards,<br />
Dapfor Team</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.dapfor.com/correct-organization-of-event-processing-in-a-separate-thread/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
