<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6433679371380083688</id><updated>2012-02-13T06:31:02.549Z</updated><category term='flash'/><category term='Visual Studio'/><category term='control'/><category term='development'/><category term='as3'/><category term='view-model'/><category term='argument'/><category term='care'/><category term='iteration'/><category term='ip'/><category term='module'/><category term='assistance'/><category term='union'/><category term='Conditional'/><category term='copy'/><category term='message'/><category term='UnhandledException'/><category term='actionscript'/><category term='UpdatePanel'/><category term='c++'/><category term='loader'/><category term='realise'/><category term='deserialize'/><category term='table'/><category term='system'/><category term='recycle'/><category term='Service'/><category term='distributed'/><category term='type'/><category term='TcpClient'/><category term='paste'/><category term='collect'/><category term='leak'/><category term='field'/><category term='memory'/><category term='Session'/><category term='IIS'/><category term='page'/><category term='LegendsOfNoobia'/><category term='AppDomain'/><category term='online'/><category term='Tween'/><category term='say'/><category term='Tetris+'/><category term='socket'/><category term='interview'/><category term='invalid cast'/><category term='StructLayout'/><category term='view'/><category term='IValueConverter'/><category term='tell'/><category term='design'/><category term='parameter'/><category term='VS'/><category term='Converter'/><category term='external'/><category term='framework'/><category term='ASP.Net'/><category term='project'/><category term='visible'/><category term='error'/><category term='content'/><category term='VS.Net'/><category term='garbage'/><category term='phone 7'/><category term='operator'/><category term='CLR'/><category term='Microsoft'/><category term='LayoutKind'/><category term='=='/><category term='support'/><category term='net'/><category term='client'/><category term='list'/><category term='iframe'/><category term='Found'/><category term='short'/><category term='messaging'/><category term='need'/><category term='InProc'/><category term='tag'/><category term='event'/><category term='Silverlight 2'/><category term='application'/><category term='XNA'/><category term='site'/><category term='interface'/><category term='Windows Phone'/><category term='Noobia'/><category term='MEF'/><category term='csharp'/><category term='Exception'/><category term='Explicit'/><category term='strong'/><category term='start'/><category term='animation'/><category term='compare'/><category term='remoting'/><category term='Convert'/><category term='LoadControl'/><category term='async'/><category term='menu'/><category term='applicaiton'/><category term='common'/><category term='share'/><category term='screen'/><category term='long'/><category term='optimize'/><category term='parse'/><category term='ref'/><category term='remote'/><category term='Component'/><category term='ChildWIndow'/><category term='Application Pool'/><category term='fight'/><category term='unhandled'/><category term='company'/><category term='Equals'/><category term='task'/><category term='investment'/><category term='log'/><category term='EF'/><category term='server'/><category term='collector'/><category term='Silverlight'/><category term='item'/><category term='show'/><category term='dialog'/><category term='MVVM'/><category term='Game'/><category term='web'/><category term='RPG'/><category term='C'/><category term='StructLayoutAttribute'/><category term='visibility'/><category term='oriented'/><category term='conditions'/><category term='Class View'/><category term='Multiple'/><category term='UpdateMode'/><category term='XAML'/><category term='angel'/><category term='param'/><category term='aspnet_wp.exe'/><category term='.net'/><category term='invest'/><category term='Always'/><category term='continuously'/><category term='distribute'/><category term='offset'/><category term='Class'/><category term='ConvertBack'/><category term='stop'/><category term='of'/><category term='WebBrowser'/><category term='tracking'/><category term='object'/><category term='AppPool'/><category term='parameters'/><category term='manage'/><category term='user'/><category term='MORPG'/><category term='ViewModel'/><category term='Synchronize'/><category term='custom'/><category term='databind'/><category term='software'/><category term='reference'/><category term='html'/><category term='investement'/><category term='Auto'/><category term='3-rd party'/><category term='Process'/><category term='serialize'/><category term='terminate'/><category term='remove'/><category term='sharp'/><category term='State'/><category term='proxy'/><category term='contract'/><category term='Architecture'/><category term='javascript'/><category term='connection'/><category term='weak'/><category term='multiplayer'/><category term='dual'/><category term='dynamic'/><category term='signature'/><category term='IT'/><category term='AJAX'/><category term='Studio'/><category term='load'/><category term='collection'/><category term='STAThread'/><category term='Domain'/><category term='repeat'/><category term='assembly'/><category term='implement'/><category term='EF 4.0'/><category term='as'/><category term='approach'/><category term='keyword'/><category term='net 4.0'/><category term='InvalidCastException'/><category term='Entity'/><category term='comparison'/><category term='handle'/><category term='NotFound'/><category term='cut'/><category term='monitor'/><category term='internet'/><category term='chat'/><category term='Not'/><category term='hide'/><category term='socket server'/><category term='Call'/><category term='heal'/><category term='enum'/><category term='idea'/><category term='innerHTML'/><category term='shout'/><category term='Thread'/><category term='static'/><category term='Visual'/><category term='own'/><category term='customize'/><category term='WP7'/><category term='enumeration'/><category term='invester'/><category term='iterate'/><category term='force'/><category term='Role'/><category term='audit'/><category term='context'/><category term='position'/><category term='constructor'/><category term='C#'/><category term='tcp'/><category term='WCF'/><category term='IPAddress'/><category term='runtime'/><category term='as2'/><category term='Singleton'/><category term='Legends'/><category term='history'/><category term='GC'/><category term='pattern'/><category term='exit'/><category term='parser'/><category term='model'/><category term='data'/><category term='MarshalByRefObject'/><category term='periodically'/><category term='money'/><category term='binding'/><title type='text'>Development ideas</title><subtitle type='html'>Value your ideas</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>40</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-1372134564224950291</id><published>2012-01-29T22:45:00.002Z</published><updated>2012-01-29T22:45:43.645Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='event'/><category scheme='http://www.blogger.com/atom/ns#' term='Domain'/><category scheme='http://www.blogger.com/atom/ns#' term='net 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='Exception'/><category scheme='http://www.blogger.com/atom/ns#' term='unhandled'/><category scheme='http://www.blogger.com/atom/ns#' term='Process'/><category scheme='http://www.blogger.com/atom/ns#' term='applicaiton'/><category scheme='http://www.blogger.com/atom/ns#' term='log'/><category scheme='http://www.blogger.com/atom/ns#' term='Component'/><category scheme='http://www.blogger.com/atom/ns#' term='UnhandledException'/><category scheme='http://www.blogger.com/atom/ns#' term='AppDomain'/><category scheme='http://www.blogger.com/atom/ns#' term='exit'/><category scheme='http://www.blogger.com/atom/ns#' term='external'/><category scheme='http://www.blogger.com/atom/ns#' term='3-rd party'/><category scheme='http://www.blogger.com/atom/ns#' term='terminate'/><title type='text'>AppDomains - Why and How ?</title><content type='html'>Finally I've found time for this post, which I was planning last year already.&lt;br /&gt;So, where you may need an AppDomain in your application, how you'll treat it and what are the benefits of using it? I'll try to answer to those question. Read further.&lt;br /&gt;Let's start from the theory: An Application Domain represents an isolated environment in a managed .net application process. Saying roughly those are sub-process layers, where the code will execute. The important features of Applicaiton Domains I'd like to mention here are the following:&lt;br /&gt;1. An applicaiton domain has its own - isolated from others, memory&lt;br /&gt;2. Those can be loaded and unloaded dynamically. Unloading an applicaiton domain will unload all the assemblies loaded in that applicaiton domain (there are still some cases when this is not true, although non-practical cases).&lt;br /&gt;Now let's try to find a usage. Imagine a scenario, where the applicaiton needs to load a component from non-trusted source. There are several issues with this, and the most important for me are Security and Reliability.&lt;br /&gt;&lt;b&gt;Security&lt;/b&gt;: you never know what the code in that component is doing behind the scenes.&lt;br /&gt;&lt;b&gt;Reliability&lt;/b&gt;: the component can be non-well designed, leaving holes for exceptions to arise.&lt;br /&gt;Let's first concentrate on the case, if we are going to handle such scenario without application domains. Of course for interaction with that third-party component there will be a well-defined interface, and every call of a method of that interface (actually an instnace of 3-rd party component, which I will call &lt;b&gt;Component X&lt;/b&gt; further) will be wrapped in a try-catch block. But what if the component does something else behind the scenes ? For example it can has a background thread which does some other processing. In this case, your handlers won't be able to handle exceptions coming from that background processed code, because those are not on the stack of a thread you've just called a method in. So what will happen ? I won't go into details here, but will say that an exception coming out from such backgroun thread (which is not properly caught in Component X, will finally take your process down, and you'll have no chance to react, cause have no handlers at all.&lt;br /&gt;Don't blame me here, cause I'm not going into some special cases here, like WinForms, where you can handle all the exceptions on the Application level by registering to ThreadException event.&lt;br /&gt;On the reliability side - you don't know what the code is doing from data-accessing perspective. So there are limited choices for you to react here - limit your own application permissions to not allow the Component X to do something wrong. But still, you will share the same address space in memory with that component.&lt;br /&gt;Ok, now let's jump to the usage of application domains for this scenario, and see how those will solve the above mentioned problems.&lt;br /&gt;First, in FCL (Framework Class Library) there is a type called AppDomain, which is handling management and interaction with application domains. So let me from now on call application domains just AppDomain for the sake of simplicity only.&lt;br /&gt;Well, the proper design for the above scenario will be the following:&lt;br /&gt;1. Create an AppDomain&lt;br /&gt;&lt;code&gt;&lt;br /&gt;AppDomain tmpDomain = AppDomain.CreateDomain("ComponentX Domain");&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;2. Register for the UnhandledException event of that AppDomain&lt;br /&gt;&lt;code&gt;&lt;br /&gt;tmpDomain.UnhandledException += new UnhandledExceptionEventHandler(OnComponentDomain_UnhandledException);&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;3. Add proper permissions to that AppDomain (this is called sandboxing - limiting permissions)&lt;br /&gt;// Leaving code for this section, because this is out of scope from this article&lt;br /&gt;4. Load the Component X assembly into that AppDomain&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Assembly tmpComponentAssembly = tmpDomain.Load(AssemblyName.GetAssemblyName("./ComponentX.dll"));&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;5. Create Component X instance in that AppDomain.&lt;br /&gt;6. Create a proxy in our AppDomain to interact with Component X instance in the new-created domain(because the memory of each AppDomain is isolated, the process of passing data between AppDomain-s involves serialization and deserialization of that data, and whole the process is refered as Marshalling).&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Type tmpComponentType = GetComponentTypeFromAssembly(tmpComponentAssembly, typeof(IComponentContract).Name);&lt;br /&gt;IComponentContract tmpComponentProxy = tmpDomain.CreateInstanceAndUnwrap(tmpComponentAssembly.FullName, tmpComponentType.FullName) as IComponentContract;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;7. After finishing working with Component X unload AppDomain of Component X to free up memory. This will also unload the assembly loaded in that AppDomain.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// This call is missing in the example solution attached to this article.&lt;br /&gt;tmpDomain.Unload();&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Great, this solves the security problem and what about the reliability? The AppDomain type (in Net Framework 4.0) defines an event called &lt;b&gt;UnhandledException&lt;/b&gt;. Unfortunately there is no way to handle that exception and continue the normal flow of the application, but the good thing here is that you get your "last-chance" to save state, or log the exception, and even schedule a task in OS to start a new instance of your application. There are several important aspects you should be aware of regarding this event: &lt;i&gt;"This event can be handled in any Applicaiton Domain, although its not necessarily raised in the application domain, where the exception occured. An exception is unhandled only if the entire stack for the thread has been unwound without finding an applicable exception handler, so the first place the event can be raised is in the application domain where the thread originated.&lt;br /&gt;If the UnhandledException event is handled in the default application domain, it is raised there for any unhandled exception in any thread, no matter what application domain the thread started in. If the thread started in an application domain that has an event handler for UnhandledException, the event is raised in that application domain. If that application domain is not the default application domain, and there is also an event handler in the default application domain, the event is raised in both application domains."&lt;/i&gt; The quoted part I've taken from MSDN documentation cause it very well explains that event propogation. I still recommend you to read the &lt;a href="http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx" target="_blank"&gt;MSDN page&lt;/a&gt;.&lt;br /&gt;In the section above I've specified the exact version of Net Framework because in the earlier versions the behavior was slightly different. Here is another section from MSDN for earlier versions: &lt;i&gt;"In the .NET Framework versions 1.0 and 1.1, an unhandled exception that occurs in a thread other than the main application thread is caught by the runtime and therefore does not cause the application to terminate. Thus, it is possible for the UnhandledException event to be raised without the application terminating. Starting with the .NET Framework version 2.0, this backstop for unhandled exceptions in child threads was removed, because the cumulative effect of such silent failures included performance degradation, corrupted data, and lockups, all of which were difficult to debug."&lt;/i&gt;&lt;br /&gt;I've also created a small solution with code representing the scenario described in this article. Click &lt;a href="https://skydrive.live.com/redir.aspx?cid=024cbf27c999610b&amp;resid=24CBF27C999610B!221&amp;parid=24CBF27C999610B!220&amp;authkey=!AOhXyxqC-KaJJxk" target="_blank"&gt;here &lt;/a&gt;to download the example codes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-1372134564224950291?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/1372134564224950291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=1372134564224950291' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/1372134564224950291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/1372134564224950291'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2012/01/appdomains-why-and-how.html' title='AppDomains - Why and How ?'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4398894542120339608</id><published>2012-01-27T15:56:00.002Z</published><updated>2012-01-27T15:56:51.255Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='operator'/><category scheme='http://www.blogger.com/atom/ns#' term='comparison'/><category scheme='http://www.blogger.com/atom/ns#' term='Equals'/><category scheme='http://www.blogger.com/atom/ns#' term='=='/><category scheme='http://www.blogger.com/atom/ns#' term='compare'/><category scheme='http://www.blogger.com/atom/ns#' term='IPAddress'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='parse'/><title type='text'>Comparing IPAddress-es</title><content type='html'>Recently I was struggling with a LINQ expression, where I had a comparison of two ip addresses. Like used to - the comparison was done by the == operator, which was the cause of the headache.&lt;br /&gt;NEVER USE == WITH IPAddress.&lt;br /&gt;Seems IPAddress have no its own overrie for ==, and because it's a reference type that operator is just comparing two addresses(whether those point to the same location in memory or not). And I was getting false for equal ip address comparison.&lt;br /&gt;You can just try to do the following:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    bool areEqual = IPAddress.Parse("150.148.1.54") == IPAddress.Parse("150.148.1.54");&lt;br /&gt;    // the areEqual now is false&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;So the proper way to compare them is to use the Equals method, which IPAddress type has an override for:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    bool areEqual = IPAddress.Parse("150.148.1.54").Equals(IPAddress.Parse("150.148.1.54"));&lt;br /&gt;    // and now the areEqual will be true&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Good luck with your coding.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4398894542120339608?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4398894542120339608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4398894542120339608' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4398894542120339608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4398894542120339608'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2012/01/comparing-ipaddress-es.html' title='Comparing IPAddress-es'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-9047645610255838461</id><published>2011-11-21T08:42:00.001Z</published><updated>2011-11-21T10:48:54.050Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='AppPool'/><category scheme='http://www.blogger.com/atom/ns#' term='Application Pool'/><category scheme='http://www.blogger.com/atom/ns#' term='IIS'/><category scheme='http://www.blogger.com/atom/ns#' term='Domain'/><category scheme='http://www.blogger.com/atom/ns#' term='Architecture'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='AppDomain'/><category scheme='http://www.blogger.com/atom/ns#' term='Process'/><category scheme='http://www.blogger.com/atom/ns#' term='aspnet_wp.exe'/><title type='text'>ASP.Net: Application Pools, Application Domains and/or processes</title><content type='html'>Hi all.&lt;br /&gt;&lt;br /&gt;Today I just wanted to bring some light on the way ASP.Net handles requests. So let's start from scratch.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;What is ASP.Net itself from OS perspective ?&lt;/b&gt;&lt;br /&gt;ASP.Net is just a process called &lt;b&gt;aspnet_wp.exe&lt;/b&gt;. How in that case it's stable against application crashes - read further.&lt;br /&gt;&lt;br /&gt;In the last question we've mentioned something called &lt;b&gt;Application&lt;/b&gt;.What is that ? Ok, Application is an atomic unit of the ASP.Net process - it's the type of the objects, which are responsible for processing client requests. But there is a good and important trick here, which ASP.Net process takes care of - the &lt;b&gt;Application Domains&lt;/b&gt;. In fact, for each application (which is represented by a vritual directory in IIS) ASP.Net creates a separate AppDomain, and everything related to specific application happens in the boundaries of that domain. This makes one Application be resistant against others' crashes.&lt;br /&gt;So for each request coming from the client, ASP.Net &lt;b&gt;"creates"&lt;/b&gt; (I will cover this a bit later) a separate Application type instance (Application object) to handle that request. Why I've quoted the &lt;b&gt;creates&lt;/b&gt; word, is because that's not the case and there is a nice optimization done under the hood: as soon as the application being started (AppDomain for that application being created), ASP.Net creates a pool of up to 100 instances of Application classes to not spend time on heavy object-creation operation on each request. So, finally, what we get, is that for each request a "random" existing Application instance processes that request.&lt;br /&gt;This brings us to one important point: &lt;b&gt;Never keep state in Application instance&lt;/b&gt;, or even if you need to take into account the fact that the instnace you've written some state to most probably will be chosen to process request from other clients as well.&lt;br /&gt;All this is great, but seems we're missing something: where do the &lt;b&gt;Application Pools&lt;/b&gt; stand in whole this architecture ? Ok, time to change your understanding about Application Pools, because those are just number of settings, which can be applied to different applications. Applicaiton Pools are just a conveniet way to group important settings alltogether and then be able to apply them to any application you'd like to.&lt;br /&gt;&lt;br /&gt;I think this is all for this post.&lt;br /&gt;Good luck in your development.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-9047645610255838461?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/9047645610255838461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=9047645610255838461' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/9047645610255838461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/9047645610255838461'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/11/aspnet-application-pools-application.html' title='ASP.Net: Application Pools, Application Domains and/or processes'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-5832699568601312675</id><published>2011-11-02T21:43:00.000Z</published><updated>2011-11-02T21:45:01.538Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='monitor'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows Phone'/><category scheme='http://www.blogger.com/atom/ns#' term='screen'/><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='development'/><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><category scheme='http://www.blogger.com/atom/ns#' term='dual'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='Tetris+'/><category scheme='http://www.blogger.com/atom/ns#' term='WP7'/><title type='text'>Better Work Environment: Bigger Screens</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-lVlJ8lWCUUM/TrG3pSU_QKI/AAAAAAAAKxw/gpoqpNjEChw/s1600/IMG_9618.JPG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="240" width="320" src="http://4.bp.blogspot.com/-lVlJ8lWCUUM/TrG3pSU_QKI/AAAAAAAAKxw/gpoqpNjEChw/s320/IMG_9618.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;It's almost 5 years I used to work on two monitors, and now sometimes feel the need of the third one. Yes, it's very handy to work on several, but there is a drawback as well: you get used to it and its getting harder and harder to work on a single one at home.&lt;br /&gt;Today, I had to spent some time on my WP7 game (which is in the Marketplace from february), and suddenly thought about moving from 22" Samsung (monitor) to 32" Samsung (TV). And you know what  - that's amazing - clear picture, wide area to work and you can see every long line of your code (I'm not fan of splitting lines by enters).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-5832699568601312675?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/5832699568601312675/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=5832699568601312675' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/5832699568601312675'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/5832699568601312675'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/11/better-work-environment-bigger-screens.html' title='Better Work Environment: Bigger Screens'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-lVlJ8lWCUUM/TrG3pSU_QKI/AAAAAAAAKxw/gpoqpNjEChw/s72-c/IMG_9618.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-7208402770131782966</id><published>2011-11-01T16:49:00.000Z</published><updated>2011-11-01T16:49:19.470Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='binding'/><category scheme='http://www.blogger.com/atom/ns#' term='show'/><category scheme='http://www.blogger.com/atom/ns#' term='Convert'/><category scheme='http://www.blogger.com/atom/ns#' term='visible'/><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><category scheme='http://www.blogger.com/atom/ns#' term='Converter'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='IValueConverter'/><category scheme='http://www.blogger.com/atom/ns#' term='visibility'/><category scheme='http://www.blogger.com/atom/ns#' term='parameters'/><category scheme='http://www.blogger.com/atom/ns#' term='Multiple'/><category scheme='http://www.blogger.com/atom/ns#' term='hide'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='ConvertBack'/><category scheme='http://www.blogger.com/atom/ns#' term='conditions'/><title type='text'>Silverlight: Control visibility based on several properties' values</title><content type='html'>Hi there.&lt;br /&gt;&lt;br /&gt;During last few months I've noticed that many people are struggling with problems like object visibility based on parameters.&lt;br /&gt;And here I will try to make this more easy for some of them.&lt;br /&gt;So, let's begin. First of all let me make a not about the IValueConverter interface, introduced in silverlight framework. That's really a very usefull contract, especially when you get used to converters. You now ask about converters ? Sure: A converter is there to help you to convert a value to match the expected result and vice-versa. That's a mechanism, which adopts the input to output, assuming that the output is fully depending on input.&lt;br /&gt;So, how does it work ? Let's assume we have the following XAML:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    &amp;lt;TextBlock Text="Dummy text" Visibility="{Binding Path=DummyTextVisibility}" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Most of the developers will go this way - trying to match the properties to the UI expectations. But this is NOT CORRECT ! Just think - You're trying to bend your logic to match the View ? Everywhere, in every study about UI development you read that separation is something everyone is trying to achieve (I mean presentation and logic separation). And here you try to adopt the logic based on presentation.&lt;br /&gt;So which is correct ? The correct way to handle this is to not think about the presentation layer at all, when you're developing the business layer. And as soon as you think this way, you see, that it would be much natural to have something like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    &amp;lt;TextBlock Text="Dummy text" Visibility="{Binding Path=IsDummyTextVisible}" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But wait... will this work ? Sure not, cause the Visibility property expecting something of type System.Windows.Visibility, and you've just passed in a bool.&lt;br /&gt;Here the Converter comes in: it lets you to bind to anything logical, and then get what you want to get from it, so it will let us write the following, assuming that we have defined BoolToVisibilityConverter:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;cnv:BoolToVisibilityConverter x:Key="boolToVisibility" /&amp;gt;&lt;br /&gt;   ...&lt;br /&gt;   &amp;lt;TextBlock Text="Dummy text" Visibility="{Binding Path=IsDummyTextVisible,Converter={StaticResource boolToVisibility}}" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We assume here also that the xmlns:cnv was imported in the root tag, and that the &lt;i&gt;&amp;lt;cnb:BoolToVisibilityConverer ...&lt;/i&gt; was defined in the resources section.&lt;br /&gt;And here is the code for the BoolToVisibilityConverter:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public class BoolToVisibilityConverter:IValueConverter&lt;br /&gt;{&lt;br /&gt;    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)&lt;br /&gt;    {&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            return (bool)value ? Visibility.Visible : Visibility.Collapsed;&lt;br /&gt;        }&lt;br /&gt;        catch (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            return Visibility.Collapsed;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)&lt;br /&gt;    {&lt;br /&gt;        /// some logic here if you're going to use this&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Great. Now we have everything in place except the thing, that in some cases you will need to make an object visible depending on two parameters - control is going to be visible if both those parameters are visible. Don't waste your time looking for some complex solutions, just wrap your control in a Panel control, and bind its visibility to the other parameter you'd like to:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;Grid Visibility="{Binding Path=SecondParameter, Converter={StaticResource boolToVisibility}}"&amp;gt;&lt;br /&gt;    &amp;lt;TextBlock Text="Dummy text" Visibility="{Binding Path=IsDummyTextVisible,Converter={StaticResource boolToVisibility}}" /&amp;gt;&lt;br /&gt;&amp;lt;Grid&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So, that's it. Enjoy :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-7208402770131782966?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/7208402770131782966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=7208402770131782966' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/7208402770131782966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/7208402770131782966'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/11/silverlight-control-visibility-based-on.html' title='Silverlight: Control visibility based on several properties&apos; values'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4707206446103094705</id><published>2011-10-20T15:08:00.000+01:00</published><updated>2011-10-20T15:08:27.038+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='constructor'/><category scheme='http://www.blogger.com/atom/ns#' term='static'/><category scheme='http://www.blogger.com/atom/ns#' term='signature'/><category scheme='http://www.blogger.com/atom/ns#' term='type'/><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><category scheme='http://www.blogger.com/atom/ns#' term='interface'/><category scheme='http://www.blogger.com/atom/ns#' term='contract'/><category scheme='http://www.blogger.com/atom/ns#' term='implement'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='force'/><category scheme='http://www.blogger.com/atom/ns#' term='net'/><category scheme='http://www.blogger.com/atom/ns#' term='CLR'/><title type='text'>Improving .Net Framework</title><content type='html'>I was thinking a lot of times about a way of forcing types to have some common constructor. Of course this can be achieved by abstract classes - but the derieved classes can hide it. So the way I was hoping it to be is through the interfaces - to be able to specify a signature of a contructor, the implementing types should have.&lt;br /&gt;Am so happy that Microsoft has Connect :) So my idea is already there - go and vote for it &lt;a href="http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2328708-enable-constructor-contracts"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Let's see what will they decide.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4707206446103094705?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4707206446103094705/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4707206446103094705' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4707206446103094705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4707206446103094705'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/10/improving-net-framework.html' title='Improving .Net Framework'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4772981516005465269</id><published>2011-10-18T00:18:00.000+01:00</published><updated>2011-10-18T00:18:16.495+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVVM'/><category scheme='http://www.blogger.com/atom/ns#' term='application'/><category scheme='http://www.blogger.com/atom/ns#' term='screen'/><category scheme='http://www.blogger.com/atom/ns#' term='online'/><category scheme='http://www.blogger.com/atom/ns#' term='share'/><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='remote'/><category scheme='http://www.blogger.com/atom/ns#' term='model'/><category scheme='http://www.blogger.com/atom/ns#' term='site'/><category scheme='http://www.blogger.com/atom/ns#' term='support'/><category scheme='http://www.blogger.com/atom/ns#' term='assistance'/><category scheme='http://www.blogger.com/atom/ns#' term='control'/><category scheme='http://www.blogger.com/atom/ns#' term='pattern'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='view-model'/><category scheme='http://www.blogger.com/atom/ns#' term='view'/><title type='text'>Remote Assistance within MVVM based applications</title><content type='html'>Even we - IT professionals, require a lot of web assistance during our daily life. One of the cases I was facing several days ago was a problem during the payment for an item in Amazon. As usual, the user calls to the support, describes the situation, gets a lot of clarifying questions, and being asked for about three times to repeat, just to ensure that he hasn't missed something.&lt;br /&gt;This is a problem - a big problem both for the customer, who is facing a problem and the support guy, who is just unable to vividly see the situation happening on the customer machine. And the thing the Support man can dreams of in those cases - is a remote connection.&lt;br /&gt;Of course in 99.9% of cases such a luxary will be impossible, and the reason is only the firewalls, the client - who doesn't even know what the remote desktop connection is, ... .&lt;br /&gt;But all we are living in an eWorld - and most of the things we do are related to the internet - onlin shopping, emails, some new account registration, blogging, ... . So I thought that there must be a better way of support, and there is. Of course, it won't fit the requirements of all the users, but it can cover most of the cases. And in this blogpost I will try to bring the idea I do have which can change the way of support.&lt;br /&gt;So let's imagine that the application, which we're adding the support for is designed using MVVM pattern. What does this mean ? This means, that whole the logic of the application is being handled by the ViewModel class instance (in simple case there can be only one class in ViewModel layer). And based on any change on that class the UI is being changed accordingly. So what if someone, who is using the same application, will be able to simulate the same changes in the same order on a ViewModel layer obects on his machine, as the user on his machine ? This will mean, that the UI on both machines will have the same state after every single change, which, in its place, means that both users will have the same view. All this is true, until there is some User-Specific logic in the appilcation, which can change the way the Application behaves depending the logged in user. Let's for now leave this open point for later discussion (in this post of course), and assume that there is a solution for this as well, and both users can log in by the same user.&lt;br /&gt;So, if we will come up with some service, which transmitts any change from one application instance to another we will have a simple screen sharing between those two users. To acomplish this we need a centralized way of transfering the changes in one ViewModel to another.&lt;br /&gt;Remember that a ViewModel class in Silverlight, implements the INotifyPropertyChanged interface, which in its place defines the PropertyChanged event. And any change which can cause the UI to update, being tranfered to the UI throught firing this event. So what we can do is by simply registering to the ViewModel class instance's PropertyChanged event, and pass any change of any property to a service (I will not go into the code, but will just concentrate on the logic here. Please write your comments to the post, and I will try to respond shortly). Transfering to the service all this data is no enough, because there must be some unique token, which by the data should be identified. And this token should be shared with the other party (The support guy in our case), so he will be able to attach his UI to that token as a listener on the service, so any change coming to the service should be transfered to the Support Application Instance (SAI later: the application instance which the support guy has onpened on his machine for remote assistance). This will now bring any UI change to the SAI.&lt;br /&gt;So in this case we got something which is very like a screen sharing application - but the actual sharing. Of course this is a lot already, and the Support guy will know now how the user goes from one point from another in the UI, but let's not stop on this, and continue developing the idea.&lt;br /&gt;Based on all this we can achieve the same from the other side, and bring any change that is being done on the SAI, to the Customer Application. This will mean already, that the application is being remotely controlled.&lt;br /&gt;And that's all. Of course I haven't spent time describing minor things like the user must first allow the Support guy to remotely see his changes, and how he is going to get that unique token, ... and a lot more, but I tryed to explain whole the working solution I do see, which I hope, can bring a big change to the online application support.&lt;br /&gt;&lt;br /&gt;All the best to all of you, and enjoy :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4772981516005465269?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4772981516005465269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4772981516005465269' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4772981516005465269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4772981516005465269'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/10/remote-assistance-within-mvvm-based.html' title='Remote Assistance within MVVM based applications'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-1197772294792608852</id><published>2011-10-13T22:35:00.002+01:00</published><updated>2011-10-13T22:35:38.062+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='investment'/><category scheme='http://www.blogger.com/atom/ns#' term='idea'/><category scheme='http://www.blogger.com/atom/ns#' term='development'/><category scheme='http://www.blogger.com/atom/ns#' term='angel'/><category scheme='http://www.blogger.com/atom/ns#' term='money'/><category scheme='http://www.blogger.com/atom/ns#' term='IT'/><category scheme='http://www.blogger.com/atom/ns#' term='invester'/><category scheme='http://www.blogger.com/atom/ns#' term='own'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><category scheme='http://www.blogger.com/atom/ns#' term='project'/><title type='text'>How I used to handle project ideas</title><content type='html'>Maybe this is usual, maybe not, but I'm used to write down all the ideas I periodically have which can make difference.&lt;br /&gt;Everything started about 5 years ago, when I've started writing down all the ideas I am having. I'll be short - they were a lot. And I was creating really big documents for each of them - describing everything there about my vision in detail. And always was hoping, that once I will find somebody - who will be interested in those, and will let me make them real, cause they mainly were really big.&lt;br /&gt;I did a lot of reading on finding investers for projects - really a lot, and several times I has been contacted by different people from different countries saying, that they want to invest. Maybe I was not so good in communication, maybe they were just trying to get the idea and go away, I don't know, but the fact is that I now feel, that the only person, who will once bring those ideas to life - is me, and nobody else will be ever such intersted in bringing them to life.&lt;br /&gt;Although now I understand that those were just dreams and nobody will ever live with those ideas, and people, event those "investers" who invest in something, are looking for money first, althought some projects are about to make lifes of many people much easier, funnier, ... .&lt;br /&gt;After so many years of looking around, I've thought about something different, because I believe - there are always many solutions for any problem, and when you think there are no ways out from some situation - be sure - there are, and think again. You now ask - what I've tried ? Ok, I've tried to do it with help of people, who share my opinions, my views and my vision. So several times I managed to find such people about 3 or 4, and we were jumping on some project. That was great, although I was getting tired a lot because that was about 3-4 hours every day after work (sometimes at nights). I was ok with that, althought people, who I was working with - were giving up after few days. Of course I understand them - they want to get money for their work, and even if they feel that the project will go live and time will set everything in its place, and they will be happy with the income, they were living by the problems they had that moment. I really understand them, and don't blame anyone of them, cause they still are my friends.&lt;br /&gt;So I do continue to collect my ideas and hope that once I will be able to make them real by my own investments. Time will show :)&lt;br /&gt;&lt;br /&gt;And thanks for following.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-1197772294792608852?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/1197772294792608852/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=1197772294792608852' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/1197772294792608852'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/1197772294792608852'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/10/how-i-used-to-handle-project-ideas.html' title='How I used to handle project ideas'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-5781278520214671599</id><published>2011-10-04T18:56:00.000+01:00</published><updated>2011-10-06T09:32:10.867+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVVM'/><category scheme='http://www.blogger.com/atom/ns#' term='show'/><category scheme='http://www.blogger.com/atom/ns#' term='ViewModel'/><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><category scheme='http://www.blogger.com/atom/ns#' term='ChildWIndow'/><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='dialog'/><title type='text'>Dialogs in MVVM (Silverlight)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Several days ago I was facing a problem, when was trying to open/show a dialog from in my MVVM application.&lt;br /&gt;The actual problem is that I want that dialog also to be bound to a ViewModel instance - controlling it.&lt;br /&gt;There are many approaches to handle this. I will present one of them - which I am satisfied with.&lt;br /&gt;So, let's start. What I want is to have a DialogViewModel instance in my main ViewModel object, which is the DataContext of the current page, and which from from I'm going to open the dialog.&lt;br /&gt;When thinking of MVVM itself you think that is much be something like setting a property and a dialog must show up - THAT IS CORRECT ! And that is what I'm going to achieve.&lt;br /&gt;So just to give a small example of code, how the structure should be:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public class PageViewModel&lt;br /&gt;{&lt;br /&gt;    private DialogViewModel dialogVM = new DialogViewModel();&lt;br /&gt;&lt;br /&gt;    public DialogViewModel DialogVM&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.dialogVM;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class DialogViewModel : INotifyPropertyChanged&lt;br /&gt;{&lt;br /&gt;    public event PropertyChangedEventHandler PropertyChanged;&lt;br /&gt;&lt;br /&gt;    private bool show = false;&lt;br /&gt;&lt;br /&gt;    private void NotifyPropertyChange(string argPropertyName)&lt;br /&gt;    {&lt;br /&gt;        PropertyChangedEventHandler tmpEH = this.PropertyChanged;&lt;br /&gt;        if(tmpEH != null)&lt;br /&gt;            tmpEH(this, new PropertyChangeEventArgs(argPropertyName));&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // Here comes a lot of logic like dialog commands, ... which I will not include in this article&lt;br /&gt;&lt;br /&gt;    public bool Show&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.show;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            if(value != this.show)&lt;br /&gt;            {&lt;br /&gt;                this.show = value;&lt;br /&gt;                this.NotifyPropertyChange("Show");&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is quiete enough for the ViewModel layer. So this is really what I've described enough. You will now ask - how should this boolean change (althought it supposed to be such thing) affect the dialog to appear - keep reading.&lt;br /&gt;The simple approach (which won't work with ChildWindow derieved dialogs) is to add a dialog definition into the XAML and bind its Visibility property to the DialogVM.Show property, using a BoolToVisibilityConverter (am sure you'll be able to write something like this yourself). But when you'll try to do this, the dialog will behabe strange - it will really be not what you wanted - and you'll notice a lot of issues with it. Maybe in further versions of Silverlight this way of showing dialogs also will be possible - but not yet.&lt;br /&gt;So, the second approach, I'll keep with, is to create a helper class, derieved from Control class. This will be the actual bridge between the DialogVM and the dialog we're going to show.&lt;br /&gt;Here what the helper control will look like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public class DialogHelper : Control&lt;br /&gt;{&lt;br /&gt;    //...&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But an empty class is not going to be any helpfull for us. And here the core of the solution is: we're going to add a DependencyProperty to this control  - to enable it to be bound to anything, bind it with the DialogVM.Show property and finally handle  the change of that dependency property.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public class DialogHelper : Control&lt;br /&gt;{&lt;br /&gt;    private static readonly DependencyProperty ShowProperty = DependencyProperty.Register("Show", typeof(bool), typeof(DialogHelper), new PropertyMetadata(false, new PropertyChangedCallback(OnShowChanged)));&lt;br /&gt;&lt;br /&gt;    private static void OnShowChanged(DependencyObject argSender, DependencyPropertyChangedEventArgs argEA)&lt;br /&gt;    {&lt;br /&gt;        ConfirmationDialogHelper tmpSender = argSender as ConfirmationDialogHelper;&lt;br /&gt;        if(tmpSender.Show)&lt;br /&gt;        {&lt;br /&gt;            DialogToShow tmpDialog = new DialogToShow();&lt;br /&gt;            //The following line makes sure that the dialog also will work based on MVVM&lt;br /&gt;            tmpDialog.DataContext = (this.DataContext as PageViewModel).DialogVM;&lt;br /&gt;            tmpDialog.Show();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So, finally, here is the way you should handle it in MVVM - ENJOY !!!&lt;br /&gt;&lt;br /&gt;P.S.&lt;br /&gt;Please sorry for any code typos, cause I was typing it right into the blog editor - with no IntelliSence support.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-5781278520214671599?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/5781278520214671599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=5781278520214671599' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/5781278520214671599'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/5781278520214671599'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/10/dialogs-in-mvvm-silverlight.html' title='Dialogs in MVVM (Silverlight)'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-6425184955401898398</id><published>2011-07-28T10:29:00.000+01:00</published><updated>2011-07-28T10:29:12.850+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Call'/><category scheme='http://www.blogger.com/atom/ns#' term='Found'/><category scheme='http://www.blogger.com/atom/ns#' term='Service'/><category scheme='http://www.blogger.com/atom/ns#' term='NotFound'/><category scheme='http://www.blogger.com/atom/ns#' term='error'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='Not'/><category scheme='http://www.blogger.com/atom/ns#' term='Exception'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><category scheme='http://www.blogger.com/atom/ns#' term='client'/><title type='text'>Silverlight - WCF: NotFound Exception</title><content type='html'>Hi all.&lt;br /&gt;&lt;br /&gt;Today I'll try to cover a problem, which many Silverlight developers are facing, trying to make WCF service calls. So the problem is that there are a lot of cases, when the client will get "NotFound" error, and here are the possible reasons for that.&lt;br /&gt;(Make a note, that I will assume that the service is actually running, and you're calling to correct endpoint).&lt;br /&gt;1. The amount of data being transfered is more than the limits - the service and clients are configured for. Remember, even if you haven't manually configured those values, there are some defaults. So this can be a cause for such an exception. &lt;a href="http://smehrozalam.wordpress.com/2009/01/29/retrieving-huge-amount-of-data-from-wcf-service-in-silverlight-application/"&gt;Here&lt;/a&gt; is a good link as a start point for this case.&lt;br /&gt;2. When a method returs something, which contains, or itself is an Enum type, and you've overriden the default values of that enum, by giving different values to its members, and there is no value with 0, then you'll have the same. This is because during serialization, if you won't assign any value to those members, which are type of the Enum, they will get default value (they are value type), which is 0 for Enums, and the Serializer will try to serialize the 0 to any of the marked values, which don't contain 0, so you'll end up by a Serialization Exception on service side, which won't be handled on client and will come back as a NotFound error.&lt;br /&gt;&lt;br /&gt;Good luck with your development.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-6425184955401898398?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/6425184955401898398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=6425184955401898398' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/6425184955401898398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/6425184955401898398'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/07/silverlight-wcf-notfound-exception.html' title='Silverlight - WCF: NotFound Exception'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-6716812109605463867</id><published>2011-07-07T18:55:00.000+01:00</published><updated>2011-07-07T18:55:23.870+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='memory'/><category scheme='http://www.blogger.com/atom/ns#' term='leak'/><category scheme='http://www.blogger.com/atom/ns#' term='handle'/><title type='text'>Memory Leaks in Silverlight Toolkit</title><content type='html'>Hi all.&lt;br /&gt;In this post I'll try to share my previous experience about memory leaks I've faced in one of projects I've working on.&lt;br /&gt;The problem was in DateTimPicker control of the Silverlight Toolkit, and also in Accordion. Seems those were not being garbage collected and causing all the stuff related to them even with event handlers to stay there in memory.&lt;br /&gt;So here are few simple tips to follow to avoid such things: Always be sure that you've unregistered any event handlers from the above mentioned controls, because those will make the objects, which in those handlers defined to also stay in memory.&lt;br /&gt;If the controls are defined in a XAML file, just remember to remove it from its parent container. All this is easily handled by a simple interface implemented on a control level (you can call it IReleasable for example), and just call the Release method (defined in this interface) from the Page's unload point. And in this method do this "detach" from the leaking control. Why the unload is not a proper place- because for a control it may fire many times - as the Load event.&lt;br /&gt;&lt;br /&gt;Good luck with Silverlight development.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-6716812109605463867?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/6716812109605463867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=6716812109605463867' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/6716812109605463867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/6716812109605463867'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/07/memory-leaks-in-silverlight-toolkit.html' title='Memory Leaks in Silverlight Toolkit'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-6666352293787420670</id><published>2011-03-18T18:04:00.000Z</published><updated>2011-03-18T18:17:03.934Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='dynamic'/><category scheme='http://www.blogger.com/atom/ns#' term='MEF'/><category scheme='http://www.blogger.com/atom/ns#' term='async'/><category scheme='http://www.blogger.com/atom/ns#' term='loader'/><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='load'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='assembly'/><title type='text'>Silverlight: MEF and other approaches</title><content type='html'>Hi all.&lt;br /&gt;&lt;br /&gt;Today I'd like to concentrate to the discussion about the MEF: a relatively new framework for dynamically loading Silverlight content.&lt;br /&gt;It was amazing from the first point of view, and we have decided to use it. The process started.&lt;br /&gt;Of course it's easy: use some simple attributes, mark the exportable types you want in your .xap packages with those attributes and that's it - you'll have them whenever you'll need them, and everything will be ok.&lt;br /&gt;Yes, all this is right, BUT ...&lt;br /&gt;There is a big BUT about this MEF: when you application will come a bit bigger - and it will come to this stage, because you are already using MEF, so that was your intention to avoid loading such a big application, you'll find out that instead of downloading each library/assembly only once from the server, you'll download it as many times, as you have it in each downloadable .XAP.&lt;br /&gt;This became a big problem, when my app with all those xaps grown to ~14Mb. What to do?&lt;br /&gt;Of course there is always a better way to go. And here one, which I have implemented and is satisfied with:&lt;br /&gt;The .Net Framework is such a good thing :) I have created a simple attribute, which was aimed to mark the assembly references for the assembly it's applied to. And the second part, is that I've created a small asynchronous Assembly Loader, which is using this information from the described attribute, and downloads all those dependencies, when you ask it to download an assembly. If this assembly is already downloaded, you'll just get that instance, otherwise it will download it, it's references, and when everything is ready to be used, it fires this amzaing "AssemblyLoaded" event, which to I was able to react. So finally, avoiding this dll duplication (another .dll hell) I've reduced the size of the app from 13.6Mb to 3.8Mb. And one more thing - it works excellent and much faster.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-6666352293787420670?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/6666352293787420670/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=6666352293787420670' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/6666352293787420670'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/6666352293787420670'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/03/silverlight-mef-and-other-approaches.html' title='Silverlight: MEF and other approaches'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-5304807342291977885</id><published>2011-02-28T20:38:00.001Z</published><updated>2011-03-01T18:39:07.111Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='application'/><category scheme='http://www.blogger.com/atom/ns#' term='context'/><category scheme='http://www.blogger.com/atom/ns#' term='cut'/><category scheme='http://www.blogger.com/atom/ns#' term='copy'/><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><category scheme='http://www.blogger.com/atom/ns#' term='paste'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='net'/><category scheme='http://www.blogger.com/atom/ns#' term='menu'/><title type='text'>Context menu in Silverlight</title><content type='html'>Hi all.&lt;br /&gt;&lt;br /&gt;Few months ago I was trying to find a standard way to implement a context menu, but could find no solution which I liked. So finally decided to write something from scratch.&lt;br /&gt;I will not go down into the details here, just will give the idea here.&lt;br /&gt;So first of all I thought, that the menu can contain several kind of items:&lt;br /&gt;1. Items, which are &lt;strong&gt;system&lt;/strong&gt;(application) &lt;strong&gt;wide&lt;/strong&gt;, and you will have them in your entire application, anywhere you'd click. The "About" menu item appears under this case.&lt;br /&gt;2. Items, which are &lt;strong&gt;based on the control type&lt;/strong&gt;, which on the user clicks the right mouse button: these can be buttons, textboxes, anything derieved from Control. Into this point I have added the Cut, Copy, Paste items for textboxes.&lt;br /&gt;3. Items, &lt;strong&gt;bound to exact controls &lt;/strong&gt;- concrete instances. In this case, only when you click on the specified instances, the items should appear there in the menu.&lt;br /&gt;&lt;br /&gt;The implementation is quite simple, so I will not include any code here. But if you'll need just write me, and I will be happy to help.&lt;br /&gt;&lt;br /&gt;So, this is all.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-5304807342291977885?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/5304807342291977885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=5304807342291977885' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/5304807342291977885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/5304807342291977885'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/02/context-menu-in-silverlight.html' title='Context menu in Silverlight'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-159478900717901993</id><published>2011-02-13T06:07:00.000Z</published><updated>2011-02-13T06:21:20.407Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='item'/><category scheme='http://www.blogger.com/atom/ns#' term='development'/><category scheme='http://www.blogger.com/atom/ns#' term='interview'/><category scheme='http://www.blogger.com/atom/ns#' term='task'/><category scheme='http://www.blogger.com/atom/ns#' term='Process'/><category scheme='http://www.blogger.com/atom/ns#' term='company'/><title type='text'>The interview I failed</title><content type='html'>It was in march 2008- in early march. I was in an interview process for Microsoft Ireland. Also, the same time, I was looking for a local job in Yerevan for the case I fail. But seems I was not been ready to fail. Anyway - the last stage of the interview to Microsoft passed. I was expecting the results. But the next day was I had to send a task, which I got from the CQG office in Yerevan to finish as a part of my interview process. I was not ablt to work on the task so good. And the next day the last tet-a-tet interview started.&lt;br /&gt;Question from the interviewer:&lt;br /&gt;-What is a thread?&lt;br /&gt;-(I was silent. Had nothing in my mind to tell them. Was absolutely empty minded and was just trying to say something but ... I was not able to.)&lt;br /&gt;-What is a process ?&lt;br /&gt;-(Again the same)&lt;br /&gt;-How would you make the program you've sent, to run better for multicore processors?&lt;br /&gt;-(Silence)&lt;br /&gt;&lt;br /&gt;Started reviewing the code I sent them:&lt;br /&gt;-Why you wrote this part in this way?&lt;br /&gt;-I really don't know, cause it is much better to write it in [telling which exactly] way.&lt;br /&gt;-Strange, you know the correct answer, but you have written in not the best way here.&lt;br /&gt;&lt;br /&gt;Here was the influence of the Microsoft on me. I was expecting the results... and was packing all my things to relocate.&lt;br /&gt;&lt;br /&gt;This was my only interview in Armenia, which, I failed. And this was stupid.&lt;br /&gt;&lt;br /&gt;This is all I'd like to share with all of you in this post. Always, when going to an interview, forget about any kind of excitement - this is the key to success.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-159478900717901993?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/159478900717901993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=159478900717901993' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/159478900717901993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/159478900717901993'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/02/interview-i-failed.html' title='The interview I failed'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-8616921463525803713</id><published>2011-02-11T11:12:00.001Z</published><updated>2011-02-11T11:14:31.447Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='phone 7'/><category scheme='http://www.blogger.com/atom/ns#' term='XNA'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><category scheme='http://www.blogger.com/atom/ns#' term='WP7'/><title type='text'>Windows Phone 7 development</title><content type='html'>Hi all.&lt;br /&gt;&lt;br /&gt;Few months ago Microsoft has announced about its new mobile platform: Windows Phone 7. And here the pursuit started. Thousands of developers started looking into it to develop something new.&lt;br /&gt;The same way I did. Decided to start from scratch a month ago - to develop a simple Tetris game. First I've investigated the market - there were several such games, but all had very small playground, which was not user friendly (by me). So the core of my idea was to make the playground as much, as the phone screen is.&lt;br /&gt;Microsoft did really good job by creating a lot of restrictions for the apps, which you are going to expose on the marketplace. There is a big doc of guideance you have to follow.&lt;br /&gt;After few days of development, when I had the game skeleton ready, I've started investigating the way to publish it. First I had to register withing the AppHub( this costs 99$). After the registration (which is not available for any country) I had to wait two weeks to be validated. One of those validation points being handled by GeoTrust (a partner company responsible for registrant validation), and this was the longest part to wait for.&lt;br /&gt;Registration is done, and the only step left is to wait until Microsoft verifies your application. This stage took them only a day. And finally, my app is on the marketplace. This is the start, and it was really easy. So I will continue my app development for WP7 - for a great mobile platform.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-8616921463525803713?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/8616921463525803713/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=8616921463525803713' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/8616921463525803713'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/8616921463525803713'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2011/02/windows-phone-7-development.html' title='Windows Phone 7 development'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4787263737157707704</id><published>2010-09-01T13:50:00.000+01:00</published><updated>2010-09-01T14:27:27.298+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EF 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='EF'/><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><category scheme='http://www.blogger.com/atom/ns#' term='tracking'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='history'/><category scheme='http://www.blogger.com/atom/ns#' term='net'/><category scheme='http://www.blogger.com/atom/ns#' term='Entity'/><category scheme='http://www.blogger.com/atom/ns#' term='audit'/><title type='text'>Audit/history tracking with EF 4.0</title><content type='html'>&lt;p&gt;I have spent last two days investigating ways to track change history for an entity. And finally came up with a good idea, which I'd like to share with everyone.&lt;br /&gt;There is a great feature in auto-generated entity code (in the entity data model designer file): support of &lt;code&gt;partial&lt;/code&gt; methods.&lt;br /&gt;For each property in an entity there are two partial methods generated:&lt;br /&gt;&lt;code&gt;On[PropertyName]Changed(), On[PropertyName]Changing({property type} value)&lt;/code&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;This is a great feature wich we are going to use.&lt;br /&gt;Let's see first when to track the changes - what is the best point to keep the history. It's not good idea to make this in the OnXXXChanged method, cause this can be caused a lot, but most of those calls will never affect the entity data. So the best time to do it is when the &lt;code&gt;SaveChanges()&lt;/code&gt; method for the Context is called. But how to handle that: The &lt;code&gt;ObjectContext&lt;/code&gt; calss, which from our datacontext class is derieved, fires an event named &lt;code&gt;SavingChanges&lt;/code&gt;, and also has a partial method, called &lt;code&gt;OnContextCreated&lt;/code&gt;.&lt;/p&gt;&lt;br /&gt;So first of all lets create a partial class with the same name and within the same namespace as the context class of our entities, and define a partial method named &lt;code&gt;OnContextCreated&lt;/code&gt; in it:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;&lt;br /&gt;public partial class MyModelEntities&lt;br /&gt;{&lt;br /&gt;    partial void OnContextCreated()&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now let's create an interface &lt;code&gt;IAuditableEntity&lt;/code&gt;, which the entities needing to track the history should implement.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;pre&gt;&lt;br /&gt;internal interface IAuditableEntity&lt;br /&gt;{&lt;br /&gt;    void AuditChanges(MyModelEntities argContext);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;This interface defines a method, which should be called, when the &lt;code&gt;SaveChanges()&lt;/code&gt; method should be called on the Context instance. In our partial context class add the following code:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;&lt;br /&gt;public partial class MyModelEntities&lt;br /&gt;{&lt;br /&gt;    partial void OnContextCreated()&lt;br /&gt;    {&lt;br /&gt;        this.SavingChanges += new EventHandler(MyModelEntities_SavingChanges);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void MyModelEntities_SavingChanges(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        IEnumerable&lt;ObjectStateEntry&gt; tmpEntries = this.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Modified);&lt;br /&gt;        foreach (ObjectStateEntry tmpEntry in tmpEntries)&lt;br /&gt;        {&lt;br /&gt;            if (tmpEntry.Entity is IAuditableEntity)&lt;br /&gt;            {&lt;br /&gt;                (tmpEntry.Entity as IAuditableEntity).AuditChanges(this);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;This code will make the Context class to call the &lt;code&gt;AuditChanges&lt;/code&gt; method of all the entities, implementing the IAuditableEntity interface before updating the datastore with new values. This means, that in the AuditChanges method body in the entity instance you will have control over the actions related to the history tracking. The other side is up to you - how to implement on the data layer the history tracking itself.&lt;br /&gt;Have fun.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4787263737157707704?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4787263737157707704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4787263737157707704' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4787263737157707704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4787263737157707704'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2010/09/audithistory-tracking-with-ef-40.html' title='Audit/history tracking with EF 4.0'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4308127668818598003</id><published>2010-03-27T05:30:00.000Z</published><updated>2010-03-27T05:39:14.809Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='application'/><category scheme='http://www.blogger.com/atom/ns#' term='InProc'/><category scheme='http://www.blogger.com/atom/ns#' term='IIS'/><category scheme='http://www.blogger.com/atom/ns#' term='Session'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='State'/><category scheme='http://www.blogger.com/atom/ns#' term='recycle'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><title type='text'>ASP.Net Session lost when deleting folder</title><content type='html'>Hi there.&lt;br /&gt;The last days of my coding brought me to a problem with loosing session state in my ASP.Net application, when deleting a folder during the request processing.&lt;br /&gt;The thing is that when you delete a folder which is under the root folder of your application, then the structure of the application is being changed, and the IIS recycles that application. This means that the issue will be only in case of InProc Session State, which keeps the session state in memory.&lt;br /&gt;Hope this will be helpfull.&lt;br /&gt;&lt;br /&gt;Have a great weekend.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4308127668818598003?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4308127668818598003/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4308127668818598003' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4308127668818598003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4308127668818598003'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2010/03/aspnet-session-lost-when-deleting.html' title='ASP.Net Session lost when deleting folder'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4933403215139420758</id><published>2010-02-26T14:01:00.000Z</published><updated>2010-02-26T14:40:47.874Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='invalid cast'/><category scheme='http://www.blogger.com/atom/ns#' term='InvalidCastException'/><category scheme='http://www.blogger.com/atom/ns#' term='control'/><category scheme='http://www.blogger.com/atom/ns#' term='Thread'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='STAThread'/><category scheme='http://www.blogger.com/atom/ns#' term='WebBrowser'/><title type='text'>Working with WebBrowser Control</title><content type='html'>One of the most interesting issues I had experienced and which for I was not able to find a solution in inet - was problem related to WebBrowser control.&lt;br /&gt;The thing is that when I was trying to access the Document property of the WebBrowser control instance, I was getting "Invalid cast exception".&lt;br /&gt;The thing is that the WebBrowser control is designed to work in one thread. So to fix this you must only check the InvokeRequired property and if it's value is true, then call the logic from the delegate, given into browser.Invoke(...) method.&lt;br /&gt;This is all the stuff.&lt;br /&gt;Lucky coding ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4933403215139420758?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4933403215139420758/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4933403215139420758' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4933403215139420758'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4933403215139420758'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2010/02/working-with-webbrowser-control.html' title='Working with WebBrowser Control'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-2417094107072079429</id><published>2010-01-18T04:43:00.000Z</published><updated>2010-01-18T05:24:53.439Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Conditional'/><category scheme='http://www.blogger.com/atom/ns#' term='UpdateMode'/><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><category scheme='http://www.blogger.com/atom/ns#' term='UpdatePanel'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='Always'/><title type='text'>ASP.Net AJAX: Working with update panels</title><content type='html'>This post is for the people, who think that using update panels is nothing else but just add it to the page. This is not true !&lt;br /&gt;&lt;br /&gt;I have noticed that a some developers are using update panels, as some kind of "metadata checkbox" - placing one update panel to wrap all the content of the page in its ContentTemplate. So in this post I will try to explain what exactly the UpdatePanels are for and how most from them.&lt;br /&gt;&lt;br /&gt;First of all UpdatePanels are markers, which let you mark small, separate updateable areas on the page. Try to look at your page as a group of functionally independent areas. Decide which areas should be updated asynchronously and wrap those area code with UpdatePanel. Don't forget to include one &amp;lt;asp:ScriptManager runat="server" ... control on the page.&lt;br /&gt;&lt;br /&gt;Job is done - you have the structure. But there is currently no difference from the page PV in what you had before (putting whole the content into one UpdatePanel) and what you currently got. Because by default The &lt;b&gt;UpdateMode&lt;/b&gt; property of the UpdatePanel is set to &lt;b&gt;Always&lt;/b&gt;, which makes the UpdatePanel to update its content on any postback. To fix this we just set the &lt;b&gt;UpdateMode&lt;/b&gt; property of the needle UpdatePanel to &lt;b&gt;Conditional&lt;/b&gt;. This makes the UpdatePanel to update its content by explicit requests (triggers, or just call to the &lt;b&gt;Update()&lt;/b&gt; method of the UpdatePanel).&lt;br /&gt;&lt;br /&gt;Now let's walk over a small example. Imagine you have a page with three UupdatePanels. All of them has some randomly generating content (random number for test). The first contains a button, which causes postback and has UpdateMode set to Always. The second also has UpdateMode set to always. The last UpdatePanel's UpdateMode is set to Conditional.&lt;br /&gt;&lt;br /&gt;Now try to click the first button. This will update both update panels (which has UpdateMode set to Always). The third UpdatePanel whill keep it's  content as was. Now click the third updatePanel's button. This will update all the three. Now add a handler to the first button's click event and call the Update() method of the third UpdatePanel). You will see that now after clicking the first button again all the updatePanels are being updated.&lt;br /&gt;&lt;br /&gt;I have also attached a small code example (like the one described above). Hope it will help you to go deeper: &lt;a href='http://www.sendspace.com/file/2lrs1w'&gt;http://www.sendspace.com/file/2lrs1w&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-2417094107072079429?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/2417094107072079429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=2417094107072079429' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2417094107072079429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2417094107072079429'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2010/01/aspnet-ajax-working-with-update-panels.html' title='ASP.Net AJAX: Working with update panels'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-2865571726334847656</id><published>2009-12-09T06:18:00.000Z</published><updated>2009-12-09T06:27:47.594Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='data'/><category scheme='http://www.blogger.com/atom/ns#' term='binding'/><category scheme='http://www.blogger.com/atom/ns#' term='event'/><category scheme='http://www.blogger.com/atom/ns#' term='custom'/><category scheme='http://www.blogger.com/atom/ns#' term='control'/><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='databind'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><title type='text'>Best place for data-binding</title><content type='html'>In the last 3 months I was involved in development of ASP.Net websites. All the projects were started when I joined them, so a lot of code was written.&lt;br /&gt;All the data-related modifications were implemented in this manner:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;    &lt;li&gt;make the databinding on page_load event&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;handle control events (button click, checkbox check, ...) and make the databinding after any change&lt;li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;This was confusing, when we have several controls causing events, which was causing to do the same databinding several times.&lt;br /&gt;So a question arised - how to reduce the number of databindings - where to make the dtabinding. And here is my answer: Do all the data-related changes on PreRender stage. This have a lot of good pooints:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;    &lt;li&gt;It runs only once per request&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;It runs after all control events, which ensures, that no more flow-changes will arise.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;This was a good solution these projects and hope it will also help some of you.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-2865571726334847656?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/2865571726334847656/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=2865571726334847656' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2865571726334847656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2865571726334847656'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2009/12/best-place-for-data-binding.html' title='Best place for data-binding'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-1508362903628052843</id><published>2009-10-06T08:55:00.000+01:00</published><updated>2009-10-06T09:01:05.009+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dynamic'/><category scheme='http://www.blogger.com/atom/ns#' term='control'/><category scheme='http://www.blogger.com/atom/ns#' term='runtime'/><category scheme='http://www.blogger.com/atom/ns#' term='LoadControl'/><category scheme='http://www.blogger.com/atom/ns#' term='user'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><title type='text'>LoadControl problem in ASP.Net</title><content type='html'>Today I met a problem and it made me angry enough to make some dumb checks and found an interesting thing conecrning the  runtime control loading. I was trying to load controls using the &lt;strong&gt;LoadControl&lt;/strong&gt; method in this way (using this overload of the method): LoadControl(type, object[]). This seemed ok - the control is being instanciated but when I was trying to access a property of it - found that all the inner controls were not loaded and I was getting NullReferenceException.&lt;br /&gt;And here was the solution - seems that the LoadControl(string) overload works much more better and using this overload you can get the required control with all its properties initialized.&lt;br /&gt;Good luck.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-1508362903628052843?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/1508362903628052843/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=1508362903628052843' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/1508362903628052843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/1508362903628052843'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2009/10/loadcontrol-problem-in-aspnet.html' title='LoadControl problem in ASP.Net'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4396177190001146045</id><published>2009-10-03T10:24:00.001+01:00</published><updated>2009-10-03T10:34:31.411+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Synchronize'/><category scheme='http://www.blogger.com/atom/ns#' term='Class View'/><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='Studio'/><category scheme='http://www.blogger.com/atom/ns#' term='VS'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual'/><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><category scheme='http://www.blogger.com/atom/ns#' term='VS.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='customize'/><title type='text'>Get all the best from VS.Net</title><content type='html'>After moving to a new company I have found that all the developers here have installed some addons on the VisualStudio.Net 2008 which make it load slower and found that they only use it for some features like outline.&lt;br /&gt;This make me to write this post about the best and also most important feature in VS.Net, which is not expsed by default (only in VS.Net 2003). This feature is just &lt;strong&gt;Class View Synchronization&lt;/strong&gt; with the class/struct, your cursor is in. So here how you can enable it.&lt;br /&gt;1. In the toolbar area right click and select &lt;strong&gt;Customize...&lt;/strong&gt; from the opened context menu.&lt;br /&gt;2. Go  to the &lt;strong&gt;Toolbars &lt;/strong&gt;tab, and enable the &lt;strong&gt;ContextMenus&lt;/strong&gt; item in the list. This will make a new toolbar appear in the toolbars.&lt;br /&gt;3. Go to the &lt;strong&gt;Commands &lt;/strong&gt;tab of the Customize window, and select the &lt;strong&gt;View&lt;/strong&gt; item in the &lt;strong&gt;Categories&lt;/strong&gt; list.&lt;br /&gt;4. Now navigate to the &lt;strong&gt;Synchronize Class View&lt;/strong&gt; item in the Commands part of the same tab. Drag it to the new added toolbars &lt;strong&gt;Editor Context Menus&lt;/strong&gt; item (a menu will appear), and drop somewhere in the &lt;strong&gt;Code Window&lt;/strong&gt; submenu.&lt;br /&gt;Here it is. Now you can use that amazing feature from your context menu.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4396177190001146045?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4396177190001146045/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4396177190001146045' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4396177190001146045'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4396177190001146045'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2009/10/get-all-best-from-vsnet.html' title='Get all the best from VS.Net'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-5002909656671125754</id><published>2009-06-09T13:37:00.000+01:00</published><updated>2009-06-09T13:43:06.101+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='investement'/><category scheme='http://www.blogger.com/atom/ns#' term='development'/><category scheme='http://www.blogger.com/atom/ns#' term='software'/><category scheme='http://www.blogger.com/atom/ns#' term='invester'/><category scheme='http://www.blogger.com/atom/ns#' term='internet'/><category scheme='http://www.blogger.com/atom/ns#' term='need'/><category scheme='http://www.blogger.com/atom/ns#' term='invest'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><category scheme='http://www.blogger.com/atom/ns#' term='project'/><title type='text'>Looking for an invester</title><content type='html'>After two years of private work, I got several project ideas, which currently are waiting for their time to be implementd. But ... they are big, and they have a lot of investments. I tried to look into different websites, which were offering some kind of "find-an-invester" solutions. But all of them were somehow alike, and had some non-friendly points in the policy. So I have decied write this blog - post and ask someone, who will read it and will be interested in investing in really good projects, which will become into huge companies later.&lt;br /&gt;&lt;br /&gt;Thanks a lot&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-5002909656671125754?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/5002909656671125754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=5002909656671125754' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/5002909656671125754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/5002909656671125754'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2009/06/looking-for-invester.html' title='Looking for an invester'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-3586902775596004719</id><published>2009-05-11T13:44:00.000+01:00</published><updated>2009-05-11T13:48:30.818+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='keyword'/><category scheme='http://www.blogger.com/atom/ns#' term='argument'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='parameter'/><category scheme='http://www.blogger.com/atom/ns#' term='ref'/><title type='text'>Underhood of the "ref" keyword</title><content type='html'>One of the most interesting keywords in C# is the &lt;strong&gt;"ref"&lt;/strong&gt; keyword. This is a argument parameter, which causes the method (indexer, constructor...) parameters to be passed by reference.&lt;br /&gt;Let's take a look to the following code snippet:&lt;br /&gt;&lt;br /&gt;public void TestFunction(int argValue)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;argValue++;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;When we pass an argument to this function a new copy of the argument is being created and the function operates on the copy - not the real object. Because the copy of a reference again points to the sane location, we get no difference using the "ref" keyword with the reference-parameters (in most cases).&lt;br /&gt;Now let's add a ref keyword before the parameter declaration:&lt;br /&gt;&lt;br /&gt;public void TestFunction(&lt;strong&gt;ref &lt;/strong&gt;int argValue)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;argValue++; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In the previous example we will get no result because the ++ operation was done on a copy of the object. But if we now pass the an integer to the function (when calling the function now, already, we have to add the "ref" keyword also here), we will get the increase of the value of the original memory, because this keyword makes the function to operate on the reference of the given parameter.&lt;br /&gt;&lt;br /&gt;And here is the most important case. Many developers see no difference in "ref" keyword when using it with reference types. But... let's now review the following interesting example:&lt;br /&gt;&lt;br /&gt;public void TestFunction(object argParam)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;argParam = null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;When entering this function the CLR will create a copy of the reference and will operated on it. But because the copied reference will refer to the same object on the heap, we will get the same result using the object's methods. And when we assign null to the argParam in the function body, we will just remove the copied reference of the parameter, which will take no modification on the real object.&lt;br /&gt;&lt;br /&gt;And now, let's add the ref keyword before the param declaration:&lt;br /&gt;&lt;br /&gt;public void TestFunction(ref object argParam)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;argParam = null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Here comes the specific behavior of the keyword. No copy of the reference is being created during function call, so when we assign a null value to the argument, we remove the original reference from the memory, and ... in the calling context - lose the reference to the object.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-3586902775596004719?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/3586902775596004719/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=3586902775596004719' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/3586902775596004719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/3586902775596004719'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2009/05/underhood-of-ref-keyword.html' title='Underhood of the &quot;ref&quot; keyword'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-2638459062451576100</id><published>2009-04-13T10:42:00.000+01:00</published><updated>2009-04-13T10:59:46.013+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='server'/><category scheme='http://www.blogger.com/atom/ns#' term='tcp'/><category scheme='http://www.blogger.com/atom/ns#' term='ip'/><category scheme='http://www.blogger.com/atom/ns#' term='distributed'/><category scheme='http://www.blogger.com/atom/ns#' term='system'/><category scheme='http://www.blogger.com/atom/ns#' term='messaging'/><category scheme='http://www.blogger.com/atom/ns#' term='message'/><category scheme='http://www.blogger.com/atom/ns#' term='distribute'/><category scheme='http://www.blogger.com/atom/ns#' term='client'/><title type='text'>Developing distributed software</title><content type='html'>After development of the first version of the "Legends Of Noobia" server (MMORPG game server, written on .Net) I thought about later  versions of it where the distributed features should be surely included. And here comes the main question - how to extend an existing application to support distribution ?&lt;br /&gt;Here what came on my mind first - distributed TCP messageing system. because this component will let me attach the same game server (for this special case, but can be any other application) instance on different servers, where the DTMS (Distributed TCP/IP Messaging Server) node will be configured and run in the same way as it was used to.&lt;br /&gt;Now let's go deeper into details to understand the idea of the DTMS. Imagine a graph, where each node is a configured instance of the system. Let's call each node a Physical Node. Each physical node is simple TCP/IP Server which accepts client connection. But - here comes the main idea - it also accepts connections from neighbour nodes (Physical Nodes from other servers, or even from the same server but another instance) and becomes a node of the distriubuted messaging graph. When a client sends a message - the server distributes this messages through all the neighbour nodes. This let's two clients, being connected to different physical nodes send/receive messages with/to each other.&lt;br /&gt;To support private messaging we can add the recepient identifier to the header of the message. Each node, receiving the message, checks whether the recepient is connected to the system through it and if so, it sends the message to the client, otherwise it distributes the message to all nodes, except the one, which from it received the message.&lt;br /&gt;In the same - easy, way the system can also support group messaging simply adding a group identifier to each message.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-2638459062451576100?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/2638459062451576100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=2638459062451576100' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2638459062451576100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2638459062451576100'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2009/04/developing-distributed-software.html' title='Developing distributed software'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4592047937256942966</id><published>2009-03-06T11:13:00.000Z</published><updated>2009-03-06T11:19:02.798Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tween'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight 2'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><title type='text'>Using previously indtroduced Tween</title><content type='html'>In my previous post I introduced a Tween class, which lets you to manipulate object Properties in timely manner.&lt;br /&gt;Let's consider we have a simple button on client area, which has "btnButton" name. The following code will change the button's width from 50 to 300 pixels in 3 seconds (3000 milliseconds).&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;    Tween tmpTween = new Tween();&lt;br /&gt;    tmpTween.MaxValue = 300;&lt;br /&gt;    tmpTween.MinValue = 50;&lt;br /&gt;    tmpTween.Period = 10000;&lt;br /&gt;    tmpTween.Target = this.btnTest;&lt;br /&gt;    tmpTween.Property = "Height";&lt;br /&gt;    tmpTween.Start();&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4592047937256942966?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4592047937256942966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4592047937256942966' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4592047937256942966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4592047937256942966'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2009/03/using-previously-indtroduced-tween.html' title='Using previously indtroduced Tween'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4379293388075491752</id><published>2009-03-06T09:34:00.001Z</published><updated>2009-03-06T09:42:38.023Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='Tween'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight 2'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='sharp'/><title type='text'>Tween in Silverlight</title><content type='html'>During my Silverlight development I noticed that I need a feature which present in Adobe Flash - the tween. It's a class which lets you to increase a property for a given object from MinValue to MaxValue in a given time period.&lt;br /&gt;So I have implemented it in C# for Silverlight 2. Here is the code for it.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;///ITween.cs - Tween support for Silverlight 2&lt;br /&gt;///The code is written by Artak Mkrtchyan&lt;br /&gt;///Exposed under GNU license at http://mkartak.blogspot.com&lt;br /&gt;///Contact me by: mkartak@gmail.com&lt;br /&gt;public interface ITween&lt;br /&gt;{&lt;br /&gt;    void Start();&lt;br /&gt;    void Stop();&lt;br /&gt;&lt;br /&gt;    double Period&lt;br /&gt;    {&lt;br /&gt;        get;&lt;br /&gt;        set;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    object Target&lt;br /&gt;    {&lt;br /&gt;        get;&lt;br /&gt;        set;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    string Property&lt;br /&gt;    {&lt;br /&gt;        get;&lt;br /&gt;        set;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    double MinValue&lt;br /&gt;    {&lt;br /&gt;        get;&lt;br /&gt;        set;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    double MaxValue&lt;br /&gt;    {&lt;br /&gt;        get;&lt;br /&gt;        set;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;///Tween.cs - Tween support for Silverlight 2&lt;br /&gt;///The code is written by Artak Mkrtchyan&lt;br /&gt;///Exposed under GNU license at http://mkartak.blogspot.com&lt;br /&gt;///Contact me by: mkartak@gmail.com&lt;br /&gt;public class Tween : ITween&lt;br /&gt;{&lt;br /&gt;    private object target;&lt;br /&gt;    private string property;&lt;br /&gt;&lt;br /&gt;    private double period;&lt;br /&gt;&lt;br /&gt;    private double minValue;&lt;br /&gt;    private double maxValue;&lt;br /&gt;&lt;br /&gt;    private bool started = false;&lt;br /&gt;    private PropertyInfo targetPropertyInfo;&lt;br /&gt;    private double currentValue;&lt;br /&gt;&lt;br /&gt;    private DispatcherTimer timer;&lt;br /&gt;&lt;br /&gt;    public Tween()&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    #region ITween Members&lt;br /&gt;&lt;br /&gt;    public void Start()&lt;br /&gt;    {&lt;br /&gt;        if (!this.started)&lt;br /&gt;        {&lt;br /&gt;            if (this.Period &lt; 0)&lt;br /&gt;            {&lt;br /&gt;                throw new ArgumentOutOfRangeException("Period must be more than zero");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            if (this.Target == null)&lt;br /&gt;            {&lt;br /&gt;                throw new ArgumentNullException("Target");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            if (this.Property == null)&lt;br /&gt;            {&lt;br /&gt;                throw new ArgumentNullException("Property");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            if (this.Property.Trim() == String.Empty)&lt;br /&gt;            {&lt;br /&gt;                throw new ArgumentException("Property must have a value");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            this.started = true;&lt;br /&gt;&lt;br /&gt;            this.targetPropertyInfo = this.Target.GetType().GetProperty(this.Property);&lt;br /&gt;            this.currentValue = this.MinValue;&lt;br /&gt;            this.timer = new DispatcherTimer();&lt;br /&gt;            this.timer.Tick += new EventHandler(this.OnTimerEvent);&lt;br /&gt;            this.timer.Interval = TimeSpan.FromMilliseconds(this.MinPeriod);&lt;br /&gt;            this.timer.Start();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void Stop()&lt;br /&gt;    {&lt;br /&gt;        if (this.started)&lt;br /&gt;        {&lt;br /&gt;            this.started = false;&lt;br /&gt;            this.timer.Stop();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public double Period&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.period;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            this.period = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public object Target&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.target;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            this.target = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public string Property&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.property;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            this.property = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public double MinValue&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.minValue;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            if (this.started)&lt;br /&gt;            {&lt;br /&gt;                throw new Exception("Unable to change value during progress");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            if (value &gt;= this.maxValue)&lt;br /&gt;            {&lt;br /&gt;                throw new ArgumentException("MinValue must be less than the maxValue");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            this.minValue = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public double MaxValue&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.maxValue;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            if (this.started)&lt;br /&gt;            {&lt;br /&gt;                throw new Exception("Unable to change value during progress");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            if (value &lt;= this.minValue)&lt;br /&gt;            {&lt;br /&gt;                throw new ArgumentException("MaxValue must be more than the minValue");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            this.maxValue = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    #endregion&lt;br /&gt;&lt;br /&gt;    private double Step&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return (this.MaxValue - this.MinValue) / StepCount;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private double Speed&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return (this.MaxValue - this.MinValue) / this.Period;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private double StepCount&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return Math.Ceiling(this.Period / this.MinPeriod);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private int MinPeriod&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return 10;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void OnTimerEvent(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (this.started)&lt;br /&gt;        {&lt;br /&gt;            lock (this)&lt;br /&gt;            {&lt;br /&gt;                this.currentValue = Math.Min(this.currentValue + this.Step, this.MaxValue);&lt;br /&gt;&lt;br /&gt;                this.targetPropertyInfo.SetValue(this.Target, this.currentValue, null);&lt;br /&gt;&lt;br /&gt;                if (this.currentValue == this.MaxValue)&lt;br /&gt;                {&lt;br /&gt;                    this.Stop();&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4379293388075491752?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4379293388075491752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4379293388075491752' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4379293388075491752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4379293388075491752'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2009/03/tween-in-silverlight.html' title='Tween in Silverlight'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-8294043142357177223</id><published>2009-02-13T19:32:00.000Z</published><updated>2009-02-13T19:41:34.663Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='LegendsOfNoobia'/><category scheme='http://www.blogger.com/atom/ns#' term='Game'/><category scheme='http://www.blogger.com/atom/ns#' term='shout'/><category scheme='http://www.blogger.com/atom/ns#' term='online'/><category scheme='http://www.blogger.com/atom/ns#' term='Role'/><category scheme='http://www.blogger.com/atom/ns#' term='fight'/><category scheme='http://www.blogger.com/atom/ns#' term='heal'/><category scheme='http://www.blogger.com/atom/ns#' term='MORPG'/><category scheme='http://www.blogger.com/atom/ns#' term='Legends'/><category scheme='http://www.blogger.com/atom/ns#' term='tell'/><category scheme='http://www.blogger.com/atom/ns#' term='say'/><category scheme='http://www.blogger.com/atom/ns#' term='Noobia'/><category scheme='http://www.blogger.com/atom/ns#' term='multiplayer'/><category scheme='http://www.blogger.com/atom/ns#' term='chat'/><category scheme='http://www.blogger.com/atom/ns#' term='of'/><category scheme='http://www.blogger.com/atom/ns#' term='RPG'/><title type='text'>Introducing LegendsOfNoobia</title><content type='html'>Legends Of Noobia is an online multi-player role-playing game (MORPG).&lt;br /&gt;After the quick registration of your character, you appear in a city center of mystical Noobia! You may communicate with other warriors, chat with those that are in the same location with you and also outside of it (such as shout which makes everyone hear your message).&lt;br /&gt;You begin moving around different locations in the world where various NPCs (non-player characters) meet you. Some are kind - just polite and hospitable citizens of Noobia, and some ... awfully angry. You&lt;br /&gt;suddenly find you in a pine forest where a green snail is crawling slowly over the leaves and a spider is looking at you from its web. And you decide to attack one of them. Started the fight and  ...&lt;br /&gt;Wooow! you killed him and gained a level ! The more you gain levels the stronger you become, and the harder it becomes to kill you. The more powerful NPCs you kill, the more experience you gain. At high levels, however, you definitely will not be able to struggle one alone against the 20 leveled Dracula sleeping in old graves, and may consider acting with a team in order to kill such a monster.&lt;br /&gt;Your goal is not just killing and gaining levels, but also fighting together with other players in a team, helping each other, by hints, messages and  most importantly - by healing.&lt;br /&gt;Check out this flash game and try out your strength by just browsing: &lt;a href='http://www.legendsofnoobia.com' target='_blank'&gt;www.legendsofnoobia.com&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-8294043142357177223?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/8294043142357177223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=8294043142357177223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/8294043142357177223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/8294043142357177223'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2009/02/introducing-my-game.html' title='Introducing LegendsOfNoobia'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-60938024250576210</id><published>2008-10-28T06:14:00.000Z</published><updated>2008-10-30T06:08:06.347Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='server'/><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='MarshalByRefObject'/><category scheme='http://www.blogger.com/atom/ns#' term='remote'/><category scheme='http://www.blogger.com/atom/ns#' term='interface'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='remoting'/><category scheme='http://www.blogger.com/atom/ns#' term='net'/><category scheme='http://www.blogger.com/atom/ns#' term='assembly'/><category scheme='http://www.blogger.com/atom/ns#' term='proxy'/><category scheme='http://www.blogger.com/atom/ns#' term='module'/><category scheme='http://www.blogger.com/atom/ns#' term='client'/><title type='text'>Remoting through interfaces</title><content type='html'>When we are going to use Remoting, we always think about the proxy classes, which should surely be deployed with the client-app. But is that the best approach?&lt;br /&gt;The OOP tells us to understand the interaction through the intercaces, this means that components should interact only by contracts. Why don’t we use this approach in Remoting. This is surely possible. And this is better approach.&lt;br /&gt;Let’s review this part of code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public class RemotedObject:MarshalByRefObject&lt;br /&gt;{&lt;br /&gt; public void SomeMethod()&lt;br /&gt; {&lt;br /&gt;  //… some code here&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Let’s update the code above and add a contract of interacting with it:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public class RemotedObject:MarshalByRefObject, IRemotedObjectContract&lt;br /&gt;{&lt;br /&gt; public void SomeMethod()&lt;br /&gt; {&lt;br /&gt;  //… some code here&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//The interface is defined in a new module&lt;br /&gt;public interface IRemotedObjectContract&lt;br /&gt;{&lt;br /&gt; void SomeMetod();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;The remoted object now can be called through IRemotedObjectContract interface. But we should place the interface definition in a separate module, so it will be referenced from the main (RemotedObject) assembly, and also it will be referenced from the client. So now, the client have not to generate a proxy class by hand and attach that module, but it will be enough just to reference the interface-owner module and all is ready. Notice, that nothing should change on the server side. But on the client side for accessing the object we will have something like:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;//…&lt;br /&gt;IRemotedObjectInterface tmpRemote = (IRemotedObjectInterface)Activator.GetObject(typeof(IRemotedObjectInterface), tmpUrl);&lt;br /&gt;//Use the retrieved tmpRemote interface to interact with the remote object&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So, this is all, and this is really good approach in .Net Remoting.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-60938024250576210?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/60938024250576210/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=60938024250576210' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/60938024250576210'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/60938024250576210'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/10/remoting-through-interfaces.html' title='Remoting through interfaces'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-6395357431531295431</id><published>2008-10-26T15:19:00.000Z</published><updated>2008-10-30T06:07:49.122Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='c++'/><category scheme='http://www.blogger.com/atom/ns#' term='StructLayoutAttribute'/><category scheme='http://www.blogger.com/atom/ns#' term='Explicit'/><category scheme='http://www.blogger.com/atom/ns#' term='offset'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='implement'/><category scheme='http://www.blogger.com/atom/ns#' term='position'/><category scheme='http://www.blogger.com/atom/ns#' term='LayoutKind'/><category scheme='http://www.blogger.com/atom/ns#' term='Auto'/><category scheme='http://www.blogger.com/atom/ns#' term='union'/><category scheme='http://www.blogger.com/atom/ns#' term='StructLayout'/><category scheme='http://www.blogger.com/atom/ns#' term='type'/><category scheme='http://www.blogger.com/atom/ns#' term='field'/><title type='text'>Implementing "C/C++" [union] in .Net</title><content type='html'>To improve performance, the CLR is capable of arranging the fields of a type any way it chooses. When you define a type, you can tell the CLR whether it must keep the type's fields in the same order as the developer specified them or whether it can reorder them as it sees fit.&lt;br /&gt;The System.Runtime.InteropServices.StructLayoutAttribute attribute is used to tell the CLR what to do (how to layout the fields). You can pass LayoutKind.Auto as a value to the above specified attribute to have the CLR arrange the fields, or LayoutKind.Sequential, to have the CLR preserve the given layout, or LayoutKind.Explicit, to explicitly arrange the fields in memory by using offsets.&lt;br /&gt;Microsoft's C# compiler selects LayoutKind.Auto for reference types, and LayoutKind.Sequential for value types.&lt;br /&gt;As was mentioned above, the StructLayoutAttribute also allows you to explicitly indicate the offset of each field by passin LayoutKind.Explicit to its constructor. Then you apply an instance of the System.Runtime.InteropServices.FieldOffsetAttribute attribute to each field passing to this attribute's constructor an Int32, indicating the offset of the field's first byte from the beginning of the instance in bytes. Here is an example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;[StructLayout(LayoutKind.Explicit)]&lt;br /&gt;public struct CUnionAlternate&lt;br /&gt;{&lt;br /&gt;   [FieldOffset(0)]&lt;br /&gt;   byte byteField;&lt;br /&gt;   [FieldOffset(0)]&lt;br /&gt;   short shortField;&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-6395357431531295431?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/6395357431531295431/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=6395357431531295431' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/6395357431531295431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/6395357431531295431'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/10/implementing-cc-union-in-net.html' title='Implementing &quot;C/C++&quot; [union] in .Net'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-3472735733912139647</id><published>2008-10-24T12:59:00.001+01:00</published><updated>2008-10-30T06:08:23.289Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='weak'/><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='collection'/><category scheme='http://www.blogger.com/atom/ns#' term='common'/><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='reference'/><category scheme='http://www.blogger.com/atom/ns#' term='strong'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='garbage'/><category scheme='http://www.blogger.com/atom/ns#' term='optimize'/><category scheme='http://www.blogger.com/atom/ns#' term='sharp'/><category scheme='http://www.blogger.com/atom/ns#' term='CLR'/><category scheme='http://www.blogger.com/atom/ns#' term='long'/><category scheme='http://www.blogger.com/atom/ns#' term='GC'/><category scheme='http://www.blogger.com/atom/ns#' term='runtime'/><category scheme='http://www.blogger.com/atom/ns#' term='collect'/><category scheme='http://www.blogger.com/atom/ns#' term='short'/><category scheme='http://www.blogger.com/atom/ns#' term='table'/><category scheme='http://www.blogger.com/atom/ns#' term='collector'/><category scheme='http://www.blogger.com/atom/ns#' term='csharp'/><title type='text'>Optimizing Garbage Collection</title><content type='html'>&lt;h2 style="text-align: center;"&gt;Weak References&lt;/h2&gt;&lt;br /&gt;There is a way to affect the performance of the garbage collection, which is introduced in .Net through the WeakReferences.&lt;br /&gt;When an object points to another one, this is called strong reference, or just reference, as we used to say, and in this case the GC will not collect that obhject as a "garbage". The WeakReferences are kind of references, the objects, which they point to can be collected, and if later they will be accessed throug the WeakReference, the access will fail.&lt;br /&gt;The managed heap contains two internal data structures whose sole purpose is to manage weak references: &lt;i&gt;short and long weak reference tables&lt;/i&gt;.&lt;br /&gt;If an object has a &lt;b&gt;short weak reference&lt;/b&gt; to itself, and is collected, then it's finalization method doesn't run, and it is being collected immediately. For the &lt;b&gt;long weak reference&lt;/b&gt;, when the garbage collector collects object pointed to by the long weak reference table only after determining that the object's storage is reclaimable. If the object has a Finalize method, the Finalize method has been called and the object was not resurrected. &lt;br /&gt;These two tables simply contain pointers to objects allocated within the managed heap. Initially, both tables are empty. When you create a WeakReference object, an object is not allocated from the managed heap. Instead, an empty slot in one of the weak reference tables is located; short weak references use the short weak reference table and long weak references use the long weak reference table.&lt;br /&gt;&lt;br /&gt;&lt;h2 style="text-align: center;"&gt;Generations&lt;/h2&gt;&lt;br /&gt;Since garbage collection cannot complete without stopping the entire program, it can cause pauses at arbitrary times during the execution of the program. Those pauses can also prevent programs from responding quickly enough to satisfy the requirements of real-time systems.&lt;br /&gt;One of the improvments of the GC is called generations. A generational garbage collector takes into account two facts:&lt;ul&gt;&lt;li&gt;Newly created objects tend to have short lives.&lt;/li&gt;&lt;li&gt;The older an object is, the longer it will survive. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Those collectors group objects by “age” and collect younger objects more often than older objects.  All new objects added to the heap can be said to be in generation “0”, until the heap gets filled up which invokes garbage collection. As most objects are short-lived, only a small percentage of “young“ objects are likely to survive their first collection. Once an object survives the first garbage collection, it gets promoted to generation “1”. Objects, which are created after some generation stage are considered as on the “0” generation. The garbage collector gets invoked next only when the sub-heap of generation “0” gets filled up. All objects in generation “1” that survive get compacted and promoted to generation “2”. All survivors in generation “0” also get compacted and promoted to generation “1”. Generation “0” then contains no objects, but, as already was mentiond”, all newer objects after GC go into generation “0”.&lt;br /&gt;Generation “2” is the maximum generation supported by the runtime's garbage collector. When future collections occur, any surviving objects currently in generation 2 simply stay in generation “2”. &lt;br /&gt;Thus, dividing the heap into generations of objects and collecting and compacting younger generation objects improves the efficiency of the basic underlying garbage collection algorithm by reclaiming a significant amount of space from the heap and also being faster than if the collector had examined the objects in all generations.&lt;br /&gt;This is all about garbage collectors, which, I think every, .Net developer must know.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-3472735733912139647?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/3472735733912139647/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=3472735733912139647' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/3472735733912139647'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/3472735733912139647'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/10/optimizing-garbage-collection.html' title='Optimizing Garbage Collection'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-2445302339660577775</id><published>2008-10-23T09:14:00.000+01:00</published><updated>2008-10-30T06:08:35.036Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='care'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='net'/><category scheme='http://www.blogger.com/atom/ns#' term='memory'/><category scheme='http://www.blogger.com/atom/ns#' term='garbage'/><category scheme='http://www.blogger.com/atom/ns#' term='leak'/><category scheme='http://www.blogger.com/atom/ns#' term='sharp'/><category scheme='http://www.blogger.com/atom/ns#' term='collector'/><title type='text'>Understanding the Garbage Collection</title><content type='html'>One of the most important parts of the .Net framework is the Garbage Collector. Instead of letting you to take care of all the memory you have used, it automatically collects all unnecessary "garbage" when it's time. But how? This is the question I am going to discuss in this article.&lt;br /&gt;&lt;br /&gt;The .NET CLR (Common Language Runtime) requires that all resources be allocated from the managed heap. The developer never need to free objects from the managed heap -they are automatically freed when they are no longer needed by the application. When the garbage collector runs, it checks for objects in the managed heap that are no longer needed by the application and performs the necessary operations to reclaim their memory. Because each type of the .Net is described by its Metadata, the garbage collector always knows, how to free up the unnecessary memory.&lt;br /&gt;So, the garbage collector starts its job by locating the roots of the application. &lt;br /&gt;&lt;br /&gt;The roots are:&lt;ul&gt;&lt;li&gt;all the global and static pointers&lt;/li&gt;&lt;li&gt;local variable pointers (which are on a thread's stack)&lt;/li&gt;&lt;li&gt;registers, which contain pointers to objects in the managed heap&lt;/li&gt;&lt;li&gt;pointers to the objects from the Freachable queue&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;The list of active roots is being maintained by the JIT compiler and CLR, and is made acceptable to the GC algorithm.&lt;br /&gt;The GC works in two phases. Let's review them in detail.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The first phase (Marking)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;(when the GC starts, it makes an assumption, that all the objects in the heap are garbage)&lt;br /&gt;&lt;ol&gt;&lt;li&gt;identification of roots&lt;/li&gt;&lt;li&gt;building the live object graph (GC runs through the roots and identifies live objects using the metadata of the objects)&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;To avoid the cycling process, if the GC tryes to add an object to the graph, which is already there, then the path, which by the object was found, is being ignored, and no more down-level searches are being made.&lt;br /&gt;When the check for all the roots is done, all the alive objects are being added into the graph, so any other objects, surely, is garbage.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;And now comes the second phase (Compacting).&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;GC walks through the heap linearly looking for garbage blocks of memory.&lt;/li&gt;&lt;li&gt;GC shifts non-garbage objects down in memory (of course, by updating all the references to the moved objects), making them easy reachable by removing all the gaps in the heap&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;After this phase the pointer is set to the end of the last object in the heap, referencing the place, where new object can be allocated on heap.&lt;br /&gt;&lt;br /&gt;&lt;h2 style="text-align: center;"&gt;Finalization&lt;/h2&gt;&lt;br /&gt;Whenever a new object, having a Finalize method, is allocated on the heap a pointer to the object is placed in an internal data structure called Finalization queue. When an object is not reachable, the garbage collector considers the object garbage. The garbage collector scans the finalization queue looking for pointers to these objects. When a pointer is found, the pointer is removed from the finalization queue and appended to another internal data structure called Freachable queue, making the object no longer a part of the garbage. At this point, the garbage collector has finished identifying garbage. The garbage collector compacts the reclaimable memory and the special runtime thread empties the freachable queue, executing each object's Finalize method.&lt;br /&gt;The next time the garbage collector is invoked, it sees that the finalized objects are truly garbage and the memory for those objects is then, simply freed.&lt;br /&gt;It is recommended to avoid using Finalize method, unless required. Finalize methods increase memory pressure by not letting the memory and the resources used by that object to be released, until two garbage collections. Since you do not have control on the order in which the finalize methods are executed, it may lead to unpredictable results.&lt;br /&gt;In my next article I will try to explain, how to optimize the GC.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-2445302339660577775?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/2445302339660577775/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=2445302339660577775' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2445302339660577775'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2445302339660577775'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/10/understanding-garbage-collection.html' title='Understanding the Garbage Collection'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-8734954718490027000</id><published>2008-10-06T13:39:00.000+01:00</published><updated>2008-10-30T06:08:47.085Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='innerHTML'/><category scheme='http://www.blogger.com/atom/ns#' term='param'/><category scheme='http://www.blogger.com/atom/ns#' term='tag'/><category scheme='http://www.blogger.com/atom/ns#' term='object'/><category scheme='http://www.blogger.com/atom/ns#' term='error'/><category scheme='http://www.blogger.com/atom/ns#' term='page'/><category scheme='http://www.blogger.com/atom/ns#' term='iframe'/><category scheme='http://www.blogger.com/atom/ns#' term='flash'/><category scheme='http://www.blogger.com/atom/ns#' term='html'/><category scheme='http://www.blogger.com/atom/ns#' term='content'/><title type='text'>Displaying IFrame contents in DIV containers</title><content type='html'>&lt;p style="text-indent: 10px;"&gt;There are a lot of situations, when we need to show a web-content from another URL on our web-site. The standard solution for these situations is the IFrame tag. But it's not good approach to use IFrame, because it's resource consuming approach. The better approach, of course, is to use DIV container, and show the needed content in it.&lt;br /&gt;That is not hard in 90% of situations, but there are special cases, when we really need help.&lt;/p&gt;&lt;br /&gt;&lt;p style="text-indent: 10px;"&gt;&lt;b&gt;The problem&lt;/b&gt; There is a flash movie on the target webpage, which takes flashvars as input, and uses them. But when we use the simple ([DIV].innerHTML = [Iframe].innerHTML) mechanism, we get for example the links not work, or some other issues with those movies.&lt;/p&gt;&lt;br /&gt;&lt;p style="text-indent: 10px;"&gt;The thing is, that when we are getting the OBJECT tag content using the &lt;i&gt;innerHTML&lt;/i&gt; property, we get it modified, but not the original content. And the problem is that the modified content removes the "flashvars" attribute content.&lt;/p&gt;&lt;br /&gt;&lt;p style="text-indent: 10px;"&gt;The solution is to use some kind of ruse. Instead of using the innerHTML property to get all the inner &lt;i&gt;PARAM&lt;/i&gt; objects, which represent the parameters, we are getting them directly through the document's getElementsByTag() method call, and passing "PARAM" as an argument. This returns the original list of params, which then can be applyed to the new created object element using &lt;b&gt;document.createElement("object")&lt;/b&gt; syntax.&lt;/p&gt;&lt;br /&gt;&lt;p style="text-indent: 10px;"&gt;But there is one more situation left. Huge number of these movies use events, which are handled by the webpages. And those scripts are being defined in the header part of the page.&lt;br /&gt;To be sure that those cases are also fixed, we should read all the script tags from the header of the page, and add them (dynamically creating new script tags on our document object, to make the browser to run through the code instructions, not to ignore them) to the header of our document.&lt;/p&gt;&lt;br /&gt;So, wish now you will never face this problem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-8734954718490027000?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/8734954718490027000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=8734954718490027000' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/8734954718490027000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/8734954718490027000'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/10/displaying-flash-movies-in-div.html' title='Displaying IFrame contents in DIV containers'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4917812117111720690</id><published>2008-09-03T03:36:00.000+01:00</published><updated>2008-09-03T04:04:07.400+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='item'/><category scheme='http://www.blogger.com/atom/ns#' term='as3'/><category scheme='http://www.blogger.com/atom/ns#' term='iterate'/><category scheme='http://www.blogger.com/atom/ns#' term='remove'/><category scheme='http://www.blogger.com/atom/ns#' term='as2'/><category scheme='http://www.blogger.com/atom/ns#' term='iteration'/><category scheme='http://www.blogger.com/atom/ns#' term='list'/><category scheme='http://www.blogger.com/atom/ns#' term='actionscript'/><category scheme='http://www.blogger.com/atom/ns#' term='as'/><title type='text'>Removing list items in AS2/AS3</title><content type='html'>&lt;span style="font-size: 12"&gt;&lt;br /&gt;Let's suppose, we have some kind of custom list, elements of which has UI representation. A big problem for the beginner developers is that when they remove the items from the list, some of them still stay there, on the stage, and function normal. They are being removed only after several remove function calls.&lt;br /&gt;Here is a code snippet describing such a situation:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class TestClass{&lt;br /&gt;     private var items:Array;&lt;br /&gt;     public function RemoveItems():void{&lt;br /&gt;          for (var i:int = 0; i &lt; this.items.length; i++){&lt;br /&gt;               RemoveItem(this.items[i]);&lt;br /&gt;          }&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public function RemoveItem(argItem:Item):void{&lt;br /&gt;          var tmpIndex:int = this.items.indexOf(argItem);&lt;br /&gt;          if (tmpIndex != -1){&lt;br /&gt;               this.items.splice(tmpIndex, 1);&lt;br /&gt;          }&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This usually happens, when the developer has already written a &lt;i&gt;RemoveItem&lt;/i&gt; function, which also removes some event handlers or cast appropriate events on Remove. And when the developer needs to clear the list he wish to use that function. That is right. But the thing here is, that using the first iteration in &lt;i&gt;RemoveItems&lt;/i&gt; function we will only iterate through about the half of all the items. The indexer &lt;i&gt;i&lt;/i&gt; will grow up, but the same time the length of the &lt;i&gt;items&lt;/i&gt; list will decrease, removing each item from it.&lt;br /&gt;Sometime this causes big problems.&lt;br /&gt;&lt;br /&gt;The best way to avoid this situation, is to use non length-dependent iteration. That is, i.e. &lt;i&gt;while&lt;/i&gt;.&lt;br /&gt;So if we just change the &lt;i&gt;for (...)&lt;/i&gt; with &lt;i&gt;while (this.items.length &gt; 0){...&lt;/i&gt; we will win.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4917812117111720690?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4917812117111720690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4917812117111720690' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4917812117111720690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4917812117111720690'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/09/removing-list-items-in-as2as3.html' title='Removing list items in AS2/AS3'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-8417386561905898482</id><published>2008-08-04T11:38:00.000+01:00</published><updated>2008-08-04T11:59:02.712+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='approach'/><category scheme='http://www.blogger.com/atom/ns#' term='oriented'/><category scheme='http://www.blogger.com/atom/ns#' term='assembly'/><category scheme='http://www.blogger.com/atom/ns#' term='module'/><title type='text'>Module-Oriented development</title><content type='html'>&lt;span style="font-face: Arial; font-size:12px"&gt;&lt;br /&gt;One of the most important aspects of the development process is the flexibility. Most developers think, that flexibility is also affects to the core of the process, but that also affects the UI of the application.&lt;br /&gt;There are situations, which in some parts (modules) of the application UI stop responding, and all the other UI elements stop responding because of that.&lt;br /&gt;This is just an example, when we need module-oriented development as the main idea for whole the development process.&lt;br /&gt;Let's start from a simple example. So we have a UI application. First of all we can define virtual blocks of UI, each of which should represent a module. For example, let's suppose we should have a search part and toolbar part on the GUI. But our application should not contain all that stuff in it. Each part should be represented by a module. So we should have a &lt;b&gt;Search Module&lt;/b&gt;, and a &lt;b&gt;Toolbar Module&lt;/b&gt;. Each module should be represented by a separete assembly.&lt;br /&gt;And our application should have a configuration file (xml), where it should keep paths for all installed modules. When it should start, it should just go through the records in the config file. For each module it should give a GUI container, where each module muust be drawn.&lt;br /&gt;During the initialization the application should initialize all the modules first and then start. Using this approach should give us ability to connect different parts of our GUI to different assemlyies. So if for exampl we have not some assemly, it should just not load. This also gives the main application ability to control all the modules work, by giving them appropriate security rules.&lt;br /&gt;Also we should be able to unload the modules, which work bad, during runtime and be error - free.&lt;br /&gt;To gain this, we must define an interface, which should be implemented by each Module. The application should work only with the interface for modules.&lt;br /&gt;&lt;br /&gt;The module-oriented development applies not only to GUI applications, but to any type of applications, which cann be represented as multi-module structure.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-8417386561905898482?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/8417386561905898482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=8417386561905898482' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/8417386561905898482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/8417386561905898482'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/08/module-oriented-development.html' title='Module-Oriented development'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-238620582800703115</id><published>2008-08-04T07:05:00.000+01:00</published><updated>2008-08-04T09:02:54.276+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='server'/><category scheme='http://www.blogger.com/atom/ns#' term='TcpClient'/><category scheme='http://www.blogger.com/atom/ns#' term='socket'/><category scheme='http://www.blogger.com/atom/ns#' term='connection'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='socket server'/><category scheme='http://www.blogger.com/atom/ns#' term='client'/><title type='text'>Simple Socket Server</title><content type='html'>&lt;p style="font-face:Arial; font-size: 12px;"&gt;&lt;br /&gt;The idea of creating a good socket-server depends on several factors, which should surely be calculated in accordance to the requirements of the given task.&lt;br /&gt;The most simple socket server exampl is the "One-Thread" server, which does all the job in its main thread. But this is not good enought for system, which should give a lot of time to each connected client to process.&lt;br /&gt;Here come the threads. In this case, each client has its own (separete) thread, which in it works, and does its tasks as long as it need. Here is the main idea of most client-server applications.&lt;br /&gt;The example project represents a simple Socket-Server, which keeps track of all connected clietns. Each client is represented by a ConnectionUser class instnace on the server. That class has a single "Run" method, which starts the processor of that client in a separete thread.&lt;br /&gt;The project is a VS.Net 2005 Solution, but I have also included the source files in the post.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size: 12px"&gt;&lt;br /&gt;##########################################################################&lt;br /&gt;############################SimpleServer.cs###############################&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Net.Sockets;&lt;br /&gt;&lt;br /&gt;namespace SimpleSocketServer&lt;br /&gt;{&lt;br /&gt;    public class SimpleServer&lt;br /&gt;    {&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// The port, to be listened for connection requests&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        private int portToListen = -1;&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// The listener object, which through the clients should connect&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        private TcpListener listener;&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Keeps the state of the server&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        private bool isStarted = false;&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// The list of connected users&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        private List&lt;ConnectionUser&gt; users = new List&lt;ConnectionUser&gt;();&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Creates an instance of a SimpleServer class&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public SimpleServer()&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Creates an instance of a SimpleServer class configured for listening the given port&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;param name="argPortToListen"&gt;The port to be listened&lt;/param&gt;&lt;br /&gt;        public SimpleServer(int argPortToListen)&lt;br /&gt;        {&lt;br /&gt;            this.PortToListen = argPortToListen;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Starts the server on the pre-specified port.&lt;br /&gt;        /// If the port was not specified, throws an Exception&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public void Start()&lt;br /&gt;        {&lt;br /&gt;            if (portToListen == -1)&lt;br /&gt;            {&lt;br /&gt;                throw new Exception("No port specified for the listener");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            isStarted = true;&lt;br /&gt;            listener = new TcpListener(this.portToListen);&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                listener.Start();&lt;br /&gt;                while (isStarted)&lt;br /&gt;                {&lt;br /&gt;                    try&lt;br /&gt;                    {&lt;br /&gt;                        //Get the TcpClient instance for the connection&lt;br /&gt;                        TcpClient tmpNewClient = listener.AcceptTcpClient();&lt;br /&gt;&lt;br /&gt;                        //Pass the retrieved object to the new processing unit&lt;br /&gt;                        //that unit in a new threads&lt;br /&gt;                        ConnectionUser tmpNewUser = new ConnectionUser(tmpNewClient);&lt;br /&gt;&lt;br /&gt;                        tmpNewUser.ConnectionClosed += new EventHandler(ConnectionUser_ConnectionClosed);&lt;br /&gt;&lt;br /&gt;                        lock (this.users)&lt;br /&gt;                        {&lt;br /&gt;                            //add the new user to the track list&lt;br /&gt;                            this.users.Add(tmpNewUser);&lt;br /&gt;                        }&lt;br /&gt;&lt;br /&gt;                        //Start processing the client in a new thread&lt;br /&gt;                        tmpNewUser.Run();&lt;br /&gt;                    }&lt;br /&gt;                    catch (Exception ex)&lt;br /&gt;                    {&lt;br /&gt;&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            catch (Exception e)&lt;br /&gt;            {&lt;br /&gt;                //Handler code here&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Handles the ConnectionClosed event of each connected user&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        /// &lt;param name="sender"&gt;The sender of the event&lt;/param&gt;&lt;br /&gt;        /// &lt;param name="e"&gt;The event arguments&lt;/param&gt;&lt;br /&gt;        protected void ConnectionUser_ConnectionClosed(object sender, EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            lock (this.users)&lt;br /&gt;            {&lt;br /&gt;                ConnectionUser tmpUser = sender as ConnectionUser;&lt;br /&gt;                tmpUser.ConnectionClosed -= new EventHandler(ConnectionUser_ConnectionClosed);&lt;br /&gt;                if (this.users.Remove(sender as ConnectionUser))&lt;br /&gt;                {&lt;br /&gt;                    Console.WriteLine("Client disconnected");&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Stops the server instance&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public void Stop()&lt;br /&gt;        {&lt;br /&gt;            this.isStarted = false;&lt;br /&gt;            this.listener.Stop();&lt;br /&gt;&lt;br /&gt;            foreach (ConnectionUser tmpUser in users)&lt;br /&gt;            {&lt;br /&gt;                tmpUser.Stop();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Gets or sets the port&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public int PortToListen&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                return this.portToListen;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                if (value &lt;= 0)&lt;br /&gt;                {&lt;br /&gt;                    throw new ArgumentOutOfRangeException();&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                this.portToListen = value;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;##########################################################################&lt;br /&gt;###########################ConnectionUser.cs##############################&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Threading;&lt;br /&gt;using System.Net.Sockets;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;namespace SimpleSocketServer&lt;br /&gt;{&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// The class, which uses a single TcpClient&lt;br /&gt;    /// connection for communication with remote host&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    public class ConnectionUser&lt;br /&gt;    {&lt;br /&gt;        public event EventHandler ConnectionClosed;&lt;br /&gt;&lt;br /&gt;        protected TcpClient connection;&lt;br /&gt;        private bool isStarted = false;&lt;br /&gt;&lt;br /&gt;        public ConnectionUser(TcpClient argClient)&lt;br /&gt;        {&lt;br /&gt;            this.connection = argClient;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Starts a new Thread and runs current instance in that thread&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public void Run()&lt;br /&gt;        {&lt;br /&gt;            Thread tmpNewThread = new Thread(new ThreadStart(StartProcessing));&lt;br /&gt;            tmpNewThread.Start();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// The processor method, which keeps whole logic of the processor unit&lt;br /&gt;        /// Must be overriden in all descendant classes.&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        protected virtual void StartProcessing()&lt;br /&gt;        {&lt;br /&gt;            isStarted = true;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Gets the Network stream of the underlying connection&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        protected Stream NetworkStream&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                return connection.GetStream();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Stops the new-thread processor&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public void Stop()&lt;br /&gt;        {&lt;br /&gt;            this.isStarted = false;&lt;br /&gt;            this.connection.Close();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Handles the connection close events&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        private void OnConnectionClose()&lt;br /&gt;        {&lt;br /&gt;            if (this.ConnectionClosed != null)&lt;br /&gt;            {&lt;br /&gt;                this.ConnectionClosed(this, null);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-238620582800703115?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/238620582800703115/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=238620582800703115' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/238620582800703115'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/238620582800703115'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/08/simple-socket-server.html' title='Simple Socket Server'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-1580256539019585744</id><published>2008-07-24T07:02:00.000+01:00</published><updated>2008-10-30T06:05:25.609Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='serialize'/><category scheme='http://www.blogger.com/atom/ns#' term='parser'/><category scheme='http://www.blogger.com/atom/ns#' term='deserialize'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='parse'/><title type='text'>(De)Serialization of simple data (parser)</title><content type='html'>&lt;p style="font-size: 14;"&gt;&lt;br /&gt;Different people are finding creating a parser quite a hard job. But the main “ring” in it is to understand not some development problem, but is to find a good representation (format) for the serializer and deserializer. This means that the hardest part of the parser is to find good delimiters for the task.&lt;br /&gt; So let’s begin from creating a parser, for a simple binary tree. Let’s suppose that each node of that tree can have two (left and right) child nodes, and also a value. Then let’s choose some simple format for serialization. Here is a simple example.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;{LeftChild|Value:RightChild}&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This will surely work, if our content (values of nodes) does not contain any characters like “:” or “{”, “}”. &lt;br /&gt;&lt;br /&gt;And now let’s look at a simple example:&lt;br /&gt;&lt;i&gt;{{{|4:}|3:{|5:{|2:}}}&lt;/i&gt;&lt;br /&gt;Let’s understand the above written example. The root node of the tree has a value of 3. It has a left child, which has value of 4 and has no child nodes – it’s a leaf node. The right child of the root node is a node, with a value of 5. It has no left child, but has a right child, which has a value of 2. And that node is also a leaf node. So now we finally have an appropriate imagination about the example given above.&lt;br /&gt;Now we can create a parser for it very easy. Most starting developers are trying to use recursive functions to create parsers, but they usually miss an important aspect, that if in that case the (for example) tree, which they are going to parse is too big, they will get a “Memory overflow” exception. This means that the best way to create a parser is to use sequential parsing algorithm.&lt;br /&gt;&lt;br /&gt;Here is the code for the upper example on C#.&lt;/p&gt;&lt;pre style="font-size: 12;"&gt;&lt;br /&gt;public class TreeNode&lt;br /&gt;{&lt;br /&gt;    public const char NODE_START = '{';&lt;br /&gt;    public const char NODE_END = '}';&lt;br /&gt;    public const char LEFT_SEPARATOR = '|';&lt;br /&gt;    public const char RIGHT_SEPARATOR = ':';&lt;br /&gt;&lt;br /&gt;    private int value;&lt;br /&gt;    private TreeNode leftChild;&lt;br /&gt;    private TreeNode rightChild;&lt;br /&gt;    private TreeNode parentNode;&lt;br /&gt;&lt;br /&gt;    public static TreeNode Parse(string argString)&lt;br /&gt;    {&lt;br /&gt;        //The format for the input node is:&lt;br /&gt;        //{[leftChild]|value:[rightChild]}&lt;br /&gt;&lt;br /&gt;        TreeNode tmpCurrentRoot = null;&lt;br /&gt;        int tmpPosition = 0;&lt;br /&gt;        ParseStage tmpStage = ParseStage.LeftChild;&lt;br /&gt;        while (tmpPosition &lt; argString.Length)&lt;br /&gt;        {&lt;br /&gt;            switch (argString[tmpPosition])&lt;br /&gt;            {&lt;br /&gt;                case NODE_START:&lt;br /&gt;                    //Create a new node with the current parent&lt;br /&gt;                    TreeNode tmpNewNode = new TreeNode(tmpCurrentRoot);&lt;br /&gt;                    if (tmpCurrentRoot != null)&lt;br /&gt;                    {&lt;br /&gt;                        if (tmpStage == ParseStage.LeftChild)&lt;br /&gt;                        {&lt;br /&gt;                            tmpCurrentRoot.LeftChild = tmpNewNode;&lt;br /&gt;                        }&lt;br /&gt;                        else if (tmpStage == ParseStage.RightChild)&lt;br /&gt;                        {&lt;br /&gt;                            tmpCurrentRoot.RightChild = tmpNewNode;&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                    //Set the pointer of current node to the new created one&lt;br /&gt;                    tmpCurrentRoot = tmpNewNode;&lt;br /&gt;                    tmpStage = ParseStage.LeftChild;&lt;br /&gt;&lt;br /&gt;                    tmpPosition++;&lt;br /&gt;                    break;&lt;br /&gt;&lt;br /&gt;                case LEFT_SEPARATOR:&lt;br /&gt;                    tmpStage = ParseStage.Value;&lt;br /&gt;                    tmpPosition++;&lt;br /&gt;                    break;&lt;br /&gt;&lt;br /&gt;                case RIGHT_SEPARATOR:&lt;br /&gt;                    tmpStage = ParseStage.RightChild;&lt;br /&gt;                    tmpPosition++;&lt;br /&gt;                    break;&lt;br /&gt;&lt;br /&gt;                case NODE_END:&lt;br /&gt;                    if (tmpCurrentRoot.ParentNode == null)&lt;br /&gt;                    {&lt;br /&gt;                        return tmpCurrentRoot;&lt;br /&gt;                    }&lt;br /&gt;                    else&lt;br /&gt;                    {&lt;br /&gt;                        if (tmpCurrentRoot == tmpCurrentRoot.ParentNode.LeftChild)&lt;br /&gt;                        {&lt;br /&gt;                            tmpStage = ParseStage.LeftChild;&lt;br /&gt;                        }&lt;br /&gt;                        else&lt;br /&gt;                        {&lt;br /&gt;                            tmpStage = ParseStage.RightChild;&lt;br /&gt;                        }&lt;br /&gt;                        tmpCurrentRoot = tmpCurrentRoot.ParentNode;&lt;br /&gt;                    }&lt;br /&gt;                    tmpPosition++;&lt;br /&gt;                    break;&lt;br /&gt;&lt;br /&gt;                default:&lt;br /&gt;                    if (tmpStage == ParseStage.Value)&lt;br /&gt;                    {&lt;br /&gt;                        string tmpValueStr = argString.Substring(tmpPosition, argString.IndexOf(RIGHT_SEPARATOR, tmpPosition) - tmpPosition);&lt;br /&gt;                        tmpCurrentRoot.Value = Int32.Parse(tmpValueStr);&lt;br /&gt;                        tmpPosition += tmpValueStr.Length;&lt;br /&gt;                        tmpStage = ParseStage.RightChild;&lt;br /&gt;                    }&lt;br /&gt;                    break;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        throw new Exception("ERROR DURING PARSING");&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public TreeNode(TreeNode argParentNode)&lt;br /&gt;    {&lt;br /&gt;        this.parentNode = argParentNode;&lt;br /&gt;        leftChild = null;&lt;br /&gt;        rightChild = null;&lt;br /&gt;        value = 0;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public int Value&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.value;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            this.value = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public TreeNode LeftChild&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.leftChild;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            this.leftChild = value;&lt;br /&gt;            if (this.leftChild != null)&lt;br /&gt;            {&lt;br /&gt;                this.leftChild.parentNode = this;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public TreeNode RightChild&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.rightChild;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            this.rightChild = value;&lt;br /&gt;            if (this.rightChild != null)&lt;br /&gt;            {&lt;br /&gt;                this.rightChild.ParentNode = this;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public TreeNode ParentNode&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return this.parentNode;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            this.parentNode = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public override string ToString()&lt;br /&gt;    {&lt;br /&gt;        string tmpResult = String.Empty;&lt;br /&gt;        tmpResult += NODE_START;&lt;br /&gt;        if (this.leftChild != null)&lt;br /&gt;        {&lt;br /&gt;            tmpResult += this.leftChild.ToString();&lt;br /&gt;        }&lt;br /&gt;        tmpResult += LEFT_SEPARATOR;&lt;br /&gt;        tmpResult += this.value;&lt;br /&gt;        tmpResult += RIGHT_SEPARATOR;&lt;br /&gt;&lt;br /&gt;        if (this.rightChild != null)&lt;br /&gt;        {&lt;br /&gt;            tmpResult += this.rightChild.ToString();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        tmpResult += NODE_END;&lt;br /&gt;        return tmpResult;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    protected enum ParseStage&lt;br /&gt;    {&lt;br /&gt;        LeftChild,&lt;br /&gt;        Value,&lt;br /&gt;        RightChild&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-1580256539019585744?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/1580256539019585744/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=1580256539019585744' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/1580256539019585744'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/1580256539019585744'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/07/deserialization-of-simple-data-parser.html' title='(De)Serialization of simple data (parser)'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-2533805866313761314</id><published>2008-06-10T08:34:00.000+01:00</published><updated>2008-06-10T08:38:39.089+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='pattern'/><category scheme='http://www.blogger.com/atom/ns#' term='design'/><category scheme='http://www.blogger.com/atom/ns#' term='implement'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Singleton'/><category scheme='http://www.blogger.com/atom/ns#' term='realise'/><title type='text'>Singleton pattern realisation</title><content type='html'>The most often meeting design pattern, which is really used, is, by me, the Singleton.&lt;br /&gt;&lt;br /&gt;And here is it's implementation on C#.&lt;br /&gt;&lt;p style="font-size: 12; font-face: Arial;"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class SingletonClass&lt;br /&gt;{&lt;br /&gt;    private static SingletonClass instance;&lt;br /&gt;&lt;br /&gt;    private SingletonClass()&lt;br /&gt;    {&lt;br /&gt;        return Instanse;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static SingletonClass Instance&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            if (instance == null)&lt;br /&gt;            {&lt;br /&gt;                instance = new SingletonClass();&lt;br /&gt;            }&lt;br /&gt;            return instance;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-2533805866313761314?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/2533805866313761314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=2533805866313761314' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2533805866313761314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2533805866313761314'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/06/singleton-pattern-realisation.html' title='Singleton pattern realisation'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-2319932452500355761</id><published>2008-05-17T05:31:00.000+01:00</published><updated>2008-05-17T06:26:03.286+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='start'/><category scheme='http://www.blogger.com/atom/ns#' term='periodically'/><category scheme='http://www.blogger.com/atom/ns#' term='manage'/><category scheme='http://www.blogger.com/atom/ns#' term='stop'/><category scheme='http://www.blogger.com/atom/ns#' term='animation'/><category scheme='http://www.blogger.com/atom/ns#' term='repeat'/><category scheme='http://www.blogger.com/atom/ns#' term='continuously'/><category scheme='http://www.blogger.com/atom/ns#' term='as2'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Process'/><title type='text'>Repeating processes and animations</title><content type='html'>During the work we meet some problems with repeating some processes or animations periodically. For exampl we have some animation, which we want to loop or some process. Here is the implementation for it. I will first write down the actionscript 2 implementation of it using non-documented Animation class, which is just a wrapper of a movieClip, with more functionality like start(), stop() and which casts "COMPLETED" event.&lt;br /&gt;We should write a class for dynamically repeat the animation until the stop method hasn't been called.&lt;br /&gt;&lt;br /&gt;&lt;div style="font-size:12"&gt;&lt;br /&gt;//AS 2.0 implementation&lt;br /&gt;class AnimRepeater{&lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private var _isStarted : Boolean;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   private var _clipName : MovieClip;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   private var _animationLoop : Animation;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   public function AnimRepeater(clipName : String) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  _clipName = clipName;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   }&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   public function start() : Void {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  if (!_isStarted) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  _isStarted = true;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  updateAnim();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   }&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   public function stop() : Void {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  if (_isStarted) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  _isStarted = false;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   }&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   private function updateAnim() : Void {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;if (_isStarted) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  var autoDelete : Boolean = true;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  _animationLoop = new Animation(_clipName, &amp;quot;animName&amp;quot;, autoDelete);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  _animationLoop.addEventListener(Animation.FINISHED, Delegate.create(this, updateAnim));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  _animationLoop.start();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   }&lt;/p&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For C# let's add some flexibility. We should use a IProcess interface, which should be used to controll the process which should be repeated.&lt;br /&gt;&lt;div style="font-size:12"&gt;&lt;br /&gt;    public delegate void ProcessEventHandler(IProcess argProcess, EventArgs argEventArgs);&lt;br /&gt;&lt;br /&gt;    interface IProcess&lt;br /&gt;&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        public event ProcessEventHandler Finished;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        public void start();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        public void stop();&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    public class ProcessRepeater : IProcess&lt;br /&gt;&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        protected bool isStarted;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        protected IProcess processToRepeat;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        public event ProcessEventHandler Finished;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        public ProcessRepeater(IProcess argProcess)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            processToRepeat = argProcess;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            isStarted = false;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        public void start()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            if (!isStarted)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                isStarted = true;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                updateProcess();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        public void stop()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            if (isStarted)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                isStarted = false;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                processToRepeat.stop();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                processToRepeat.Finished -= new ProcessEventHandler(updateProcess);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        protected void updateProcess()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            if (isStarted)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                processToRepeat.Finished += new ProcessEventHandler(updateProcess);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                processToRepeat.start();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        private void updateProcess(IProcess argProcess, EventArgs argEventArgs)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            updateProcess();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-2319932452500355761?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/2319932452500355761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=2319932452500355761' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2319932452500355761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/2319932452500355761'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/05/repeating-processes-and-animations.html' title='Repeating processes and animations'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6433679371380083688.post-4332923237946342225</id><published>2008-05-13T10:22:00.000+01:00</published><updated>2008-05-14T05:32:55.043+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='enum'/><category scheme='http://www.blogger.com/atom/ns#' term='enumeration'/><category scheme='http://www.blogger.com/atom/ns#' term='as2'/><category scheme='http://www.blogger.com/atom/ns#' term='implement'/><category scheme='http://www.blogger.com/atom/ns#' term='actionscript'/><category scheme='http://www.blogger.com/atom/ns#' term='as'/><title type='text'>Enumerations in ActionScript 2.0</title><content type='html'>Here is an alternate for Enumerations in ActionScript 2.0. Just add an item with needed name as a member to the class (as _NORMAL or _ENUM_ITEM) and then use them through the "get" functions from another code.&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* @author Artak Mkrtchyan&lt;br /&gt;*/&lt;br /&gt;class EnumTypeName extends Number&lt;br /&gt;{&lt;br /&gt;private static var _NORMAL:EnumTypeName = EnumTypeName(0);&lt;br /&gt;private static var _ENUM_ITEM:EnumTypeName = EnumTypeName(1);&lt;br /&gt;&lt;br /&gt;private function EnumTypeName(value:Number){&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static function get NORMAL() : EnumTypeName {&lt;br /&gt;return _NORMAL;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static function get _ENUM_ITEM() : EnumTypeName {&lt;br /&gt;return _ENUM_ITEM;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;////////////////////////////////&lt;br /&gt;//And here is the usage of this&lt;br /&gt;&lt;br /&gt;//.... another class&lt;br /&gt;public function test():Void{&lt;br /&gt;var testVar:EnumTypeName;&lt;br /&gt;&lt;br /&gt;testVar = EnumTypeName.NORMAL;&lt;br /&gt;}&lt;br /&gt;//.... other code&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6433679371380083688-4332923237946342225?l=mkartak.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mkartak.blogspot.com/feeds/4332923237946342225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6433679371380083688&amp;postID=4332923237946342225' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4332923237946342225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6433679371380083688/posts/default/4332923237946342225'/><link rel='alternate' type='text/html' href='http://mkartak.blogspot.com/2008/05/enumerations-in-actionscript-20.html' title='Enumerations in ActionScript 2.0'/><author><name>Artak Mkrtchyan</name><uri>https://profiles.google.com/112646501118334043311</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-1IlDeQc1Pb8/AAAAAAAAAAI/AAAAAAAAAAA/f_XFH4REA9Y/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry></feed>
