Fórum Visual C# GeneralGeneral discussion and questions regarding Visual C# -- including best practices on developing with C# in VS, documentation, setup, and samples.© 2009 Microsoft Corporation. Todos os direitos reservados.Mon, 30 Nov 2009 14:48:57 Z24becc9b-b984-47b2-a748-a62e38c0066fhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/603c5a01-0ac3-4cc5-8135-7117df227505http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/603c5a01-0ac3-4cc5-8135-7117df227505get2kshhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=get2kshOut of Memory ExceptionHi,<br/> <br/> my application is having multi-threaded components to compare set of data which is a prolonging process, am getting out of memory exceptions often in some systems. <br/> <br/> please give some common strategies to address this item..<br/> <br/>Thu, 19 Nov 2009 18:14:50 Z2009-11-30T14:48:57Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/c8cae84b-ee7d-4c80-80af-22ed234ea203http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/c8cae84b-ee7d-4c80-80af-22ed234ea203Hamed_1983http://social.msdn.microsoft.com/Profile/pt-BR/?user=Hamed_1983how to detect primary key column in dataTable ?Hi<br/>how to detect pk column(s) in dataTable ?<br/>thanks<hr class="sig">http://www.codeproject.com/KB/codegen/DatabaseHelper.aspxMon, 30 Nov 2009 11:31:42 Z2009-11-30T14:48:25Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/37b2bedc-1b85-4585-bf05-23bda0de7f12http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/37b2bedc-1b85-4585-bf05-23bda0de7f12LetsGoNativehttp://social.msdn.microsoft.com/Profile/pt-BR/?user=LetsGoNativeRegExI need to know the regex pattern to find specific numbers..lets say [0-3] which means I want to make sure the string contains, 0 and 1 and 2 and 3. Any help?Fri, 27 Nov 2009 23:31:36 Z2009-11-30T14:43:44Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/fb0b8fa4-cf3d-42b5-99f3-b73959e95d9dhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/fb0b8fa4-cf3d-42b5-99f3-b73959e95d9dclayenderhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=clayenderc# interop and office versionsHi<br/>I have a C# application that creates and displays an Excel spreadsheet, it was built on a PC with office 2007.<br/><br/>My problem is that when I try and load it onto a PC that has an earlier version of Office I get an error message....<br/><br/>Application requires that assembly Microsoft.vbe.Interop version 12.0 be installed in the Global Assembly Cache first.....<br/><br/>Does this mean my application will only run on PC's with Office2007 or can I load this required assembly onto the target PC?<br/>Mon, 30 Nov 2009 12:32:40 Z2009-11-30T14:30:12Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/9f09d242-6721-4574-a608-6e779673d15dhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/9f09d242-6721-4574-a608-6e779673d15dExistance0http://social.msdn.microsoft.com/Profile/pt-BR/?user=Existance0open command promptI'm trying to get command prompt to open from a forms application and run a but of code the window should stay open but I will need to close it with a button eventually. The following code doesn't seem to work for me can someone tell me what I am doing wrong?<br/> <br/> <pre lang="x-c#">Process p = new Process(); p.Start(&quot;CMD.exe&quot;, &quot;echo hi\recho 2\r&quot;);</pre>Sun, 29 Nov 2009 20:15:00 Z2009-11-30T14:24:21Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/d0528b07-de80-41a2-835d-55562158773ehttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/d0528b07-de80-41a2-835d-55562158773eMconwayhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=MconwayCreating a Shortcut using WshShellClass in C#Hopefully this is a very simple solution..<br/> <br/> I am trying to create a function that generates a shortcut to the desktop, and it works.. However.. the path I am trying to use causes the shortcut creator to throw an exception..<br/> <br/> <pre lang="x-c#"> WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut; shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(@Environment.GetEnvironmentVariable(&quot;USERPROFILE&quot;) + &quot;\\Desktop\\QPS_Punch_Clock.lnk&quot;); shortcut.TargetPath = &quot;C:\\Program Files\\Internet Explorer\\iexplore.exe -k &quot;+Properties.Settings.Default.URL; shortcut.Save();<br/> </pre> The error I am getting is very generic: Value does not fall within the expected range.<br/> <br/> The TargetPath is the culprit, I am unsure how to proceed. I am trying to generate shortcuts that open IE and Kiosk mode.. with whatever URL was specified. If I remove the Properties.Settings.Default.URL concatenation from the Target Path.. the shortcut is created but is a broken link.. because it is set to <pre lang="x-c#">&quot;C:\Program Files\Internet Explorer\iexplore.exe -k &quot;</pre> <br/> I can also make a working shortcut using only the URL Property, but it obviously is not opening in kiosk mode..<br/> <br/> Does anyone have any ideas?<br/> <br/> Thanks!<br/>Wed, 25 Nov 2009 18:41:06 Z2009-11-30T14:21:35Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/a317d08c-dddc-4082-aaaa-99d51972acechttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/a317d08c-dddc-4082-aaaa-99d51972acecTJStuttgarthttp://social.msdn.microsoft.com/Profile/pt-BR/?user=TJStuttgartGetting event handlers (list of delegates) of a WinForm control<div>I do like to get the registered event handlers for a certain event of a WinForm control, e.g. Enter. There are solutions by using reflection e.g. <a href="http://blogs.interakting.co.uk/steve/archive/2008/05/19/NET--Hacking-events-and-manipulating-delegates.aspx">http://blogs.interakting.co.uk/steve/archive/2008/05/19/NET--Hacking-events-and-manipulating-delegates.aspx</a></div> <div><br/></div> <div>So what it basically does, is to retrieve a private field with the same name as the event, e.g. &quot;Enter&quot;. This works very well with &quot;my own classes&quot;. Via the EventInfo I do get the declaring class (for WinForm components mostly Control). </div> <div><br/></div> <div> <pre lang="x-c#">EventInfo eventInfo = t.GetEvent(eventName, BindingFlags.Instance | BindingFlags.NonPublic)</pre> </div> <div>This also proofs in my case, that there is no typo with the name, since I get eventInfo. However, when then trying to access the private field &quot;Event&quot; on Control, I do not get any FieldInfo returned. Obviously the events are somehow different located as in &quot;my classes&quot;.</div> <div><br/></div> <div>Did some manage to get the list of delegates for a certain control event?</div> <div><br/></div>Mon, 30 Nov 2009 13:48:27 Z2009-11-30T13:57:04Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/15514c1a-b6a1-44f5-a06c-9b029c4164d7http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/15514c1a-b6a1-44f5-a06c-9b029c4164d7toddhdhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=toddhdSearching a byte array for a pattern of bytes<p>I am reading a binary file into a one dimensional byte array. Now I need to search that array for a pattern of bytes. </p> <p>In other words, this is the equivilent of String.IndexOf()</p> <p>I want to search the binary array and return the index of the subvalue that I searched for.</p> <p>For whatever reason, I'm having trouble wrapping my head around this. Can anyone give me an example of how to achieve this?</p>Sun, 04 Jun 2006 20:39:38 Z2009-11-30T13:54:41Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/b89c5002-e14d-439d-a8e8-1d106970f339http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/b89c5002-e14d-439d-a8e8-1d106970f339Ravish_Khttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Ravish_KHow to print each node of xml fileHi,<br/> <br/> I have xml file in which each node has many child nodes and again each child node has many childs and so on. I need to print each node name and value of xml document.  I want to do in c# language. Can any one tell me how to traverse xml file.<br/> <br/> Here is example of xml file<br/> <br/> <br/> &lt;data&gt;<br/>   &lt;file&gt;<br/>      &lt;name&gt;gunjan.txt&lt;/name&gt;<br/>      &lt;path&gt;c://temp&lt;/path&gt;<br/>   &lt;/file&gt;<br/> &lt;file&gt;<br/>      &lt;name&gt;kajal.txt&lt;/name&gt;<br/>      &lt;path&gt;c://temp&lt;/path&gt;<br/>   &lt;/file&gt;<br/> &lt;/data&gt;<br/> <br/>Sun, 29 Nov 2009 15:07:51 Z2009-11-30T13:35:37Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/08ed4e96-1f9b-4765-85d1-5fa9a2db99eahttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/08ed4e96-1f9b-4765-85d1-5fa9a2db99eaBliznahttp://social.msdn.microsoft.com/Profile/pt-BR/?user=BliznaVS Express - deploying different than ClickOnce?Hi,<br/>I would like to create deployment for my app with the setup but I cannot find Setup project that I could add. The only way seems to be Publish. What am I missing? ThanksMon, 30 Nov 2009 13:34:42 Z2009-11-30T13:34:42Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/c8fa99a6-0151-4898-82e8-79665d8cbd76http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/c8fa99a6-0151-4898-82e8-79665d8cbd76Power-Mosfethttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Power-MosfetPanel with background Image<p>Hello,</p> <p>i have a Panel with background picture it shows (only the Click half), and the question is how the show the other half only with a click of an button.<br/> <span class="short_text"><span style="background-color:#ffffff" title=tekenen><br/> </span> </span></p> <p><img src="http://img690.imageshack.us/img690/2622/62913458.png" alt=num1></p> <br/>Fri, 27 Nov 2009 21:15:23 Z2009-11-30T12:57:54Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/d537e230-c36f-41ad-a2b9-ee82a20ade56http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/d537e230-c36f-41ad-a2b9-ee82a20ade56tiauhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=tiauscreen resolution i think made a big mistake when i design my GUI.<br/>When i design my GUI, i only care on  screen resolution of my working PC. As i port to other PC, i just to saw the problem ... the size of the GUi not same as in my working PC.<br/><br/>Basically, I'd created a Gui in usercontrol; in that control i place two picture boxes side by side which one's width is 1020 and the other is 205. This scales are working good in my working PC (screen resolution = 1280 x 768)<br/><br/>So my question is how do i make those scale fit to any PC ( e.g. 1900 x 1200) ? What suppose should i do? I would like all the design scale to fit with 1900 x 1200. <br/>Should i use Dock properties? I cant find dock properties in usercontrol.<br/><br/>Please Guide.<br/>Thanks.Mon, 30 Nov 2009 09:19:57 Z2009-11-30T12:53:28Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/b38bde31-748b-4f40-8632-a094f066f009http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/b38bde31-748b-4f40-8632-a094f066f009M Rajeehttp://social.msdn.microsoft.com/Profile/pt-BR/?user=M%20Rajeedraw consecutive polygon <p class=MsoNormal style="margin:0in 0in 10pt"><span style="font-family:Times New Roman;font-size:x-small">Hi,</span></p> <p class=MsoNormal style="margin:0in 0in 10pt"><span style="font-size:x-small"><span style="font-family:Times New Roman"><span>   </span>I want to draw consecutive polygon of similar side inside a given polygon (of any number of sides-regular or irregular polygon) at a specified distance (varies).</span></span></p> <p class=MsoNormal style="margin:0in 0in 10pt"><span style="font-family:Times New Roman;font-size:x-small">When the space inside the polygon is not enough to draw another polygon, I should stop drawing polygon.</span></p> <p class=MsoNormal style="margin:0in 0in 10pt"><span style="font-family:Times New Roman;font-size:x-small">Can anyone tell me how to detect whether the a polygon at specified distance can be drawn inside the polygon or not.</span></p> <p class=MsoNormal style="margin:0in 0in 10pt"><span style="font-family:Times New Roman;font-size:x-small">Thank you</span></p> <p class=MsoNormal style="margin:0in 0in 10pt"><span style="font-family:Times New Roman;font-size:x-small">M Rajee</span></p>Mon, 30 Nov 2009 07:02:53 Z2009-11-30T12:43:38Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/a341c107-7da5-49c3-952f-749427ad0098http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/a341c107-7da5-49c3-952f-749427ad0098Bliznahttp://social.msdn.microsoft.com/Profile/pt-BR/?user=BliznaWhy there is app.config file if its only for reading?Hi,<br/>I do not understand why there has to be app.config file in the release directory, because when setting is changes it is being saved to appdata directory relatively to Win user. If its only for reading, why its not embedded in the app? I have tried to embed it and released app works, but debugging doesnt (ConfigurationErrorException). I am trying to have as less files as possible.<br/>ThanksMon, 30 Nov 2009 09:23:51 Z2009-11-30T12:36:13Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/c93e8e3d-f877-49f0-b552-64137c980abchttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/c93e8e3d-f877-49f0-b552-64137c980abcRyan McBeehttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Ryan%20McBeeMethod Name Expected Compile Error - Windows Service Timer ProjectI have a Window Service project that has a timer.  I have a line of code in the Timer Event that kicks off a method.  However, I am having trouble passing through my parameters in this line.  I am getting a compile error that reads &quot;Method Name Expected&quot;.  Any thoughts?<br/><br/><span style="font-size:x-small"><font size=2> <p>_timer.Elapsed +=</p> </font></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">new</span></span><span style="font-size:x-small"> System.Timers.</span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">ElapsedEventHandler</span></span><span style="font-size:x-small">(MoveFiles(</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">@&quot;C:\temp&quot;</span></span><span style="font-size:x-small">,</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">@&quot;C:\temp&quot;</span></span><span style="font-size:x-small">,</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">&quot;*.txt&quot;</span></span><span style="font-size:x-small">));<br/><br/>My method called MoveFiles is defined as follows;<br/><br/><span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">public</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">static</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">void</span></span><span style="font-size:x-small"> MoveFiles(</span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">string</span></span><span style="font-size:x-small"> sourceDir, </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">string</span></span><span style="font-size:x-small"> destinationDir, </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">string</span></span><span style="font-size:x-small"> pattern) <p>{</p> <font size=2> <p> </p> </font></span></p> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">var</span></span><span style="font-size:x-small"> fileQuery = </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">from</span></span><span style="font-size:x-small"> f </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">in</span></span><span style="font-size:x-small"> </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Directory</span></span><span style="font-size:x-small">.GetFiles(sourceDir, pattern)<font size=2> <p> </p> </font></span></p> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">select</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">new</span></span><span style="font-size:x-small"> {Source = f,Destination = </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Path</span></span><span style="font-size:x-small">.Combine(destinationDir, </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Path</span></span><span style="font-size:x-small">.GetFileName(f))}; <p> </p> <font size=2> <p>fileQuery.ToList().ForEach(f =&gt;</p> </font></span></p> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">File</span></span><span style="font-size:x-small">.Move(f.Source, f.Destination)); <p>}<br/><br/>Any help is appreciated!<br/><br/>Thanks,<br/>Ryan</p> </span></p> </span></p>Sun, 29 Nov 2009 17:29:00 Z2009-11-30T11:53:41Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/46d10549-0010-4b41-930b-e110382d70cchttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/46d10549-0010-4b41-930b-e110382d70ccChristopher Piszhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Christopher%20Piszdataviewgrid - binding keeps adding more columnsI created a dataview grid in the designer to layout my UI.<br/>I leave it empty until I am ready to display data to the user. I wanted the user to see the control and the column headings from the start though.<br/>So, I defiend the columns of the grid in the designer.<br/><br/>Now while my application is running the user clicks a button, I handle the event:<br/>Create a dataset, create its tables, fill the tables, bind the grid to one of the tables.<br/><br/>My problem is that whenever I go through the steps to bind the grid to my new table<br/>1) It adds all the columns from the new table to its already defined columns, doubling its number of columns.<br/>2) It uses the DataColumn.ColumnName property insead of the DataColumn.Caption property that I would expect.<br/><br/>My steps are simply:<br/><br/>//...grid is already shown and has column names from form init time<br/>grid.DataSource = null;<br/>CreatesMyDataSet();<br/>m_myDataSet.Tables[&quot;myTable&quot;] ;<br/><br/>How can I solve those problems?<br/>Sun, 29 Nov 2009 22:29:13 Z2009-11-30T11:48:01Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/1ba3c325-fc3f-44f8-b8dd-8360966cc170http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/1ba3c325-fc3f-44f8-b8dd-8360966cc170Bruno Piauihttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Bruno%20PiauiI'm having trouble clicking on an automatically alert (javascript) using a WebBrowser component in C#.<span class="long_text"><span title="Olá,">Hello,<br/> </span> <span title="Estou usando um componente (WebBrowser) para abrir uma URL de terceiros e fazer algumas ações, como preencher automaticamente os campos em um formulário e clicar no botão enviar também automaticamente.">I'm using a component (WebBrowser) to open a URL from third parties and do some actions, such as automatically populate fields in a form and click the submit button also automatically.<br/> </span> <span style="background-color:#ffffff" title="O problema é que a página que eu acesso foi alterada e cada vez que ela abre roda um javascript onload na tag BODY com um alert que bloqueia a continuação do meu processo de preenchimento e envio do formulário automaticamente.">The problem is that the page that I access has changed and every time she opens a wheel javascript onload in BODY tag with an alert that blocks the continuation of my process of completing and submitting the form automatically.<br/> </span> <span style="background-color:#ffffff" title="É possível clicar automaticamente em um alert ou simular o &quot;ENTER&quot; no botão de confirmação??">You can click on an alert automatically or simulate the &quot;ENTER&quot; button for confirmation?<br/> <br/> </span> <span style="background-color:#ffffff" title="PS: Essa é uma aplicação desktop feita em C# com framwork NET 3.5">PS: This is a desktop application made in C # with NET 3.5 framwork</span> </span>Tue, 24 Nov 2009 12:28:30 Z2009-11-30T11:47:22Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/cbef41eb-02cf-42ee-afda-a2b6034ac876http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/cbef41eb-02cf-42ee-afda-a2b6034ac876naturefreak827http://social.msdn.microsoft.com/Profile/pt-BR/?user=naturefreak827How can I select the current paragraph in a richtextbox?My question is the same as the one in this thread <a href="http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/df8de69f-0ae6-44f6-8c79-57bc4327d519">http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/df8de69f-0ae6-44f6-8c79-57bc4327d519</a>. I tried to use the answer chosen there, but could not get it to work. I replied on that thread to try to get some more help but it already had an answer marked so no one responded. <div><br/></div> <div><br/></div>Mon, 30 Nov 2009 02:51:57 Z2009-11-30T11:44:40Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/88359a50-6834-4d8a-b993-d068acfd5af3http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/88359a50-6834-4d8a-b993-d068acfd5af3Akram El Assashttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Akram%20El%20AssasOpen-Closed Principle in C#Hi I would like to illustrate the Open-Closed Principle. I'm asking my self about how to use C1 and C2 methods in A withouth modifing the class A.<br/> <br/> Thanks.<br/> <br/> Here is my code :<br/> <br/> <pre lang="x-c#">using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace OuvertureFermeture { interface I { void sub_foo(); void sub_bar(); } class C1 : I { #region I Membres public void sub_foo() { Console.WriteLine(&quot;sub_foo : C1&quot;); } public void sub_bar() { Console.WriteLine(&quot;sub_bar : C1&quot;); } #endregion } class C2 : I { #region I Membres public void sub_foo() { Console.WriteLine(&quot;sub_foo : C2&quot;); } public void sub_bar() { Console.WriteLine(&quot;sub_bar : C1&quot;); } #endregion } class A { private I _C { get; set; } public void foo() { _C.sub_foo(); } public void bar() { _C.sub_bar(); } public A() { } } class Program { static void Main(string[] args) { //A a = new A(); //a.foo(); //a.bar(); } } } </pre> <br/>Tue, 24 Nov 2009 20:39:56 Z2009-11-30T11:24:01Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/42c1a60c-4506-4167-a091-4910d4e07eachttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/42c1a60c-4506-4167-a091-4910d4e07eacSimon Woodshttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Simon%20WoodsCOM Interop - switching to STA Threading - how to?Hi<br/> <br/> I am working on a web service whose business layer has a hybrid of COM  and .Net business objects. I can get the data from the .net business objects fine. I have tests which prove that the COM business objects work fine when accessing them from VS2008's test suite. However, when I try and access them via the web service, an error is generated. (Exception from HResult: 0x800A0062). I managed to replicate this problem using various testing scenarios and got rid of the problem by explicitly setting the threading to STA. <br/> <br/> So I figured that, when invoking any of my COM methods, I first need to switch to an STA Thread.<br/> <br/> I am struggling to know how to do this. I have tried 2 methods.<br/> <br/> a) Getting hold of the current  thread and setting its apartment state to STA, but that generates an error on the development server<br/> b)  Explicitly trying to create a new STA thread. Here's my code ... but be warned I'm a threading newbie!<br/> <br/> <br/> public class STATaskExecutor<br/>     {<br/> <br/>         static Thread _thread;<br/>         static MyCOMDLL.CFactory _factory;<br/>         static MyCOMDLLTypes.IMyCOMType _myCOMObject;<br/>         static string _var1;<br/>         static string _var2;<br/>         static string _var3;<br/>         static bool _created;<br/>        <br/>         public static MyCOMDLLTypes.IMyCOMType CreateCOMObject(MyCOMDLL.CFactory p_factory, string p_param1, string p_param2, string p_param3)<br/>         {<br/>             _factory = p_factory;<br/>             _var1 = p_param1;<br/>             _var2 = p_param2;<br/>             _var3 = p_param3;<br/> <br/>             _thread = new Thread(CreateCOMObjectInstance);<br/>             _thread.SetApartmentState(ApartmentState.STA);<br/>             _thread.Start();<br/>            <br/>             while (!_created){ }<br/>            <br/>             return _COMObject;<br/>         }<br/> <br/>         [STAThread]<br/>         private static void CreateCOMObjectInstance()<br/>         {<br/>             try<br/>             {<br/>                 _COMObject = _factory.CreateIMyInterface(_var1, _var2, _var3;<br/>             }<br/>             catch (Exception ex)<br/>             {<br/>                <br/>             }<br/>             finally<br/>             {<br/>                 _created = true;<br/>                 _thread = null;           <br/>             }<br/>         }<br/> <br/> I am finding that the CreateCOMObjectInstance executes, but it is failing with the same error.<br/> <br/> a) Could it be failing for some other reason?<br/> b) Where am I going wrong in relation to the implementation of creating an new  STA thread<br/> (finally but non-essentially since it doesn't work)<br/> c) Is there a more elegant ways of passing around the COM function (e.g. as a first class function). I don't know if you can pass round COM methods as first class functions!<br/> <br/> Many thanks<br/> <br/> SimonFri, 27 Nov 2009 19:17:51 Z2009-11-30T12:36:45Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/81569b7b-b917-415d-b2c8-773cd7a41c9ehttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/81569b7b-b917-415d-b2c8-773cd7a41c9eAndy C Chttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Andy%20C%20CDelegates and References to classesHi<br/> <br/> If I have the following code:<br/> <br/> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">class</span> A { <br/> <span style="color:Blue">public</span> A(Action&lt;<span style="color:Blue">int</span> &gt; myDelegate) { MyDelegate = myDelegate; } Action&lt;<span style="color:Blue">int</span> &gt; MyDelegate {<span style="color:Blue">get</span> ; <span style="color:Blue">private</span> s<span style="color:Blue">et</span> ;} } <span style="color:Blue"><br/> class</span> B { <br/> <span style="color:Blue">public</span> B(Action&lt;<span style="color:Blue">int</span> &gt; myDelegate) { MyDelegate = myDelegate; } Action&lt;<span style="color:Blue">int</span> &gt; MyDelegate {<span style="color:Blue">get</span> ; <span style="color:Blue">private</span> <span style="color:Blue">set</span> ;} }</pre> </div> <br/> If I do:<br/> <br/> <div style="color:Black;background-color:White"> <pre> Action&lt;<span style="color:Blue">int</span> &gt; action = i =&gt; DoSomething(i); A = <span style="color:Blue">new</span> A(action); B = <span style="color:Blue">new</span> B(A.MyDelegate); </pre> </div> <br/> Will the class B be created with the reference to the underlying delegate or will it keep a reference to class A? As if it keeps a reference to class A and I want class A to be garbage collected it could create a memory leak as long as B is alive.<br/> <br/> Thank youSat, 28 Nov 2009 18:39:12 Z2009-11-30T11:02:26Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/91806e54-e551-4f92-91a2-77e25c6ce88chttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/91806e54-e551-4f92-91a2-77e25c6ce88cCompetitiveDadhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=CompetitiveDadActive Directory Password Stop ListI need to write a custom password filter for AD that will read a list of stop words from something like a file or a registry entry.<br/><br/>My skills are really in .NET and in particular in C# but all the examples I've seen are in C++ obviously and are around RegEx rather than stop words.<br/><br/>Does anyone have a basic .NET one that I can take and play with that presumably gets wrapped in a CCW or something?<br/><br/>Thanks,<br/><br/>MartinFri, 27 Nov 2009 11:43:18 Z2009-11-30T10:48:34Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/88b2bd0d-aeb6-40f5-8fef-342ba24ee90dhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/88b2bd0d-aeb6-40f5-8fef-342ba24ee90dsrinivas.ghttp://social.msdn.microsoft.com/Profile/pt-BR/?user=srinivas.gRejecting incomming call in c#Hi, I am developing a windows mobile application in c# where i need to reject the incoming call on some condition is there any way for rejecting the incoming call.can i get some pointers regarding this.<br/> <br/> Thanks in advance.Mon, 30 Nov 2009 05:26:23 Z2009-11-30T11:51:42Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/c829ff10-aaeb-42e0-bbe3-97c349e8e740http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/c829ff10-aaeb-42e0-bbe3-97c349e8e740M Rajeehttp://social.msdn.microsoft.com/Profile/pt-BR/?user=M%20RajeeDetermine direction of specified point<span style="line-height:115%;font-family:'Verdana', 'sans-serif';color:black"><span style="font-size:x-small"> <p class=MsoNormal style="line-height:150%;margin:0in 0in 10pt"><span style="line-height:150%;font-family:'Verdana', 'sans-serif';color:black">Hi,<br/>I want to produce a  a compensating equivalent of a continuous poly-line at specified distance apart the given poly-line in the specified direction of the point given. Poly-line can be drawn as they like and can take any shape, closed or open.</span></p> <p class=MsoNormal style="line-height:150%;margin:0in 0in 10pt"><span style="line-height:150%;font-family:'Verdana', 'sans-serif';color:black"><br/>I just what to determine whether the specified point is on which side. Refer the link below for Pictorial view</span></p> <p class=MsoNormal style="line-height:150%;margin:0in 0in 10pt"><span style="line-height:150%;font-family:'Verdana', 'sans-serif';color:black"><a href="http://www.kodakgallery.com/gallery/creativeapps/slideShow/Main.jsp?token=146826487113:1204117644&amp;cm_mmc=site_email-_-new_site_share-_-core-_-View_photos_link">http://www.kodakgallery.com/gallery/creativeapps/slideShow/Main.jsp?token=146826487113%3A1204117644&amp;cm_mmc=site_email-_-new_site_share-_-core-_-View_photos_link</a></span></p> <p class=MsoNormal style="line-height:150%;margin:0in 0in 10pt"><span style="line-height:150%;font-family:'Verdana', 'sans-serif';color:black">Otherwise is there any other approach to do so? Provide Sample.<br/><br/>Thank You<br/>M Rajee</span></p> <span style="line-height:115%;font-family:'Verdana', 'sans-serif';color:black"><span style="font-size:x-small"> <p class=MsoNormal style="margin:0in 0in 10pt"> </p> </span></span></span> <p class=MsoNormal style="margin:0in 0in 10pt"> </p> </span><br/>Mon, 30 Nov 2009 10:22:40 Z2009-11-30T10:22:41Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/3dbc2208-4085-4bfc-9bec-26a5b47b49b2http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/3dbc2208-4085-4bfc-9bec-26a5b47b49b2aniruddha84http://social.msdn.microsoft.com/Profile/pt-BR/?user=aniruddha84how to check the checkbox column in WPF datagrid ??hi all ,<br/><br/>i hav added the one column in WPF datagrid as checkbox.<br/><br/>i  wann to know that hw can i check the each row in datagrid is checked or not ??<br/><br/>thx in advanceMon, 30 Nov 2009 10:19:44 Z2009-11-30T10:19:45Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/77504ef3-d15f-4d3e-9e27-c6d6267434d9http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/77504ef3-d15f-4d3e-9e27-c6d6267434d9WOnder93http://social.msdn.microsoft.com/Profile/pt-BR/?user=WOnder93Video compression driver not responding to SendMessage() functionHi, <div><br/> <div>I'm trying to connect my C# program to a webcam.</div> <div><br/></div> <div>I've done everything necessary to connect to my webcam and everything is working fine - I am able to retrieve video data from the webcam, but it's compressed, so I need to use the proper video compression driver to decompress it into RGB.</div> <div><br/></div> <div>And here begins my problem:</div> <div>I'm using the ICOpen() function from msvfw32.dll to find the driver I need. It returns a non-zero handle to a driver. But whenever I try to send a message to it, it just returns 0 and does nothing with the passed parameters (e.g. with messages like ICM_GETINFO or ICM_DECOMPRESS_GET_FORMAT).</div> <div><br/></div> <div>I don't know what I'm doing wrong - I've seen some other C# and VB programs that do it the same way and they didn't experience such problem.</div> <div><br/></div> <div>I've been trying also the ICLocate() function but with the same result. Maybe the problem is the driver. I don't know :-(</div> <div><br/></div> <div>By the way, the compression that uses my webcam is YUY2.</div> <div><br/></div> <div>Here is the source code (The problem is in the Capture.Device.Connect() method):</div> <div> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">using</span> System; <span style="color:Blue">using</span> System.Collections.Generic; <span style="color:Blue">using</span> System.Linq; <span style="color:Blue">using</span> System.Text; <span style="color:Blue">using</span> System.Runtime.InteropServices; <span style="color:Blue">using</span> System.Drawing; <span style="color:Blue">namespace</span> Capture { <span style="color:Blue">public</span> <span style="color:Blue">delegate</span> <span style="color:Blue">void</span> FrameCallback(Bitmap bmp); <span style="color:Blue">public</span> <span style="color:Blue">class</span> Device { <span style="color:Blue">#region</span> Structures [StructLayout(LayoutKind.Sequential)] <span style="color:Blue">struct</span> ICINFO { <span style="color:Blue">int</span> dwSize; <span style="color:Blue">int</span> fccType; <span style="color:Blue">int</span> fccHandler; <span style="color:Blue">int</span> dwFlags; <span style="color:Blue">int</span> dwVersion; <span style="color:Blue">int</span> dwVersionICM; <span style="color:Blue">unsafe</span> <span style="color:Blue">fixed</span> <span style="color:Blue">char</span> name[16]; <span style="color:Blue">unsafe</span> <span style="color:Blue">fixed</span> <span style="color:Blue">char</span> desc[256]; <span style="color:Blue">unsafe</span> <span style="color:Blue">fixed</span> <span style="color:Blue">char</span> driver[256]; } [StructLayout(LayoutKind.Sequential)] <span style="color:Blue">struct</span> BITMAPINFO { <span style="color:Blue">public</span> <span style="color:Blue">int</span> biSize; <span style="color:Blue">public</span> <span style="color:Blue">int</span> biWidth; <span style="color:Blue">public</span> <span style="color:Blue">int</span> biHeight; <span style="color:Blue">public</span> <span style="color:Blue">short</span> biPlanes; <span style="color:Blue">public</span> <span style="color:Blue">short</span> biBitCount; <span style="color:Blue">public</span> <span style="color:Blue">int</span> biCompression; <span style="color:Blue">public</span> <span style="color:Blue">int</span> biSizeImage; <span style="color:Blue">public</span> <span style="color:Blue">int</span> biXPelsPerMeter; <span style="color:Blue">public</span> <span style="color:Blue">int</span> biYPelsPerMeter; <span style="color:Blue">public</span> <span style="color:Blue">int</span> biClrUsed; <span style="color:Blue">public</span> <span style="color:Blue">int</span> biClrImportant; <span style="color:Blue">public</span> <span style="color:Blue">static</span> BITMAPINFO Default { <span style="color:Blue">get</span> { BITMAPINFO bi = <span style="color:Blue">new</span> BITMAPINFO(); bi.biSize = 40; bi.biPlanes = 1; bi.biBitCount = 24; <span style="color:Blue">return</span> bi; } } <span style="color:Green">//public int[] ColorTable;</span> } [StructLayout(LayoutKind.Sequential)] <span style="color:Blue">struct</span> VIDEOHDR { <span style="color:Blue">public</span> IntPtr lpData; <span style="color:Green">// Pointer to locked data buffer</span> <span style="color:Blue">public</span> <span style="color:Blue">uint</span> dwBufferLength; <span style="color:Green">// Length of data buffer</span> <span style="color:Blue">public</span> <span style="color:Blue">uint</span> dwBytesUsed; <span style="color:Green">// Bytes actually used</span> <span style="color:Blue">public</span> <span style="color:Blue">uint</span> dwTimeCaptured; <span style="color:Green">// Milliseconds from start of stream</span> <span style="color:Blue">public</span> <span style="color:Blue">uint</span> dwUser; <span style="color:Green">// For client's use</span> <span style="color:Blue">public</span> <span style="color:Blue">uint</span> dwFlags; <span style="color:Green">// Assorted flags (see defines)</span> [MarshalAs(UnmanagedType.SafeArray)] <span style="color:Blue">byte</span>[] dwReserved; <span style="color:Green">// Reserved for driver</span> } [StructLayout(LayoutKind.Sequential)] <span style="color:Blue">struct</span> CAPSTATE { <span style="color:Blue">public</span> <span style="color:Blue">uint</span> uiImageWidth; <span style="color:Blue">public</span> <span style="color:Blue">uint</span> uiImageHeight; <span style="color:Blue">public</span> <span style="color:Blue">int</span> fLiveWindow; <span style="color:Blue">public</span> <span style="color:Blue">int</span> fOverlayWindow; <span style="color:Blue">public</span> <span style="color:Blue">int</span> fScale; <span style="color:Blue">public</span> <span style="color:Blue">int</span> ptScrollx; <span style="color:Blue">public</span> <span style="color:Blue">int</span> ptScrolly; <span style="color:Blue">public</span> <span style="color:Blue">int</span> fUsingDefaultPalette; <span style="color:Blue">public</span> <span style="color:Blue">int</span> fAudioHardware; <span style="color:Blue">public</span> <span style="color:Blue">int</span> fCapFileExists; <span style="color:Blue">public</span> <span style="color:Blue">int</span> dwCurrentVideoFrame; <span style="color:Blue">public</span> <span style="color:Blue">int</span> dwCurrentVideoFramesDropped; <span style="color:Blue">public</span> <span style="color:Blue">int</span> dwCurrentWaveSamples; <span style="color:Blue">public</span> <span style="color:Blue">int</span> dwCurrentTimeElapsedMS; <span style="color:Blue">public</span> IntPtr hPalCurrent; <span style="color:Blue">public</span> <span style="color:Blue">int</span> fCapturingNow; <span style="color:Blue">public</span> <span style="color:Blue">int</span> dwReturn; <span style="color:Blue">public</span> <span style="color:Blue">uint</span> wNumVideoAllocated; <span style="color:Blue">public</span> <span style="color:Blue">uint</span> wNumAudioAllocated; } <span style="color:Blue">#endregion</span> <span style="color:Blue">delegate</span> <span style="color:Blue">void</span> CallbackGetFrame(IntPtr hwnd, <span style="color:Blue">ref</span> VIDEOHDR videoHeader); <span style="color:Blue">#region</span> Constants <span style="color:Blue">const</span> <span style="color:Blue">int</span> GWL_EXSTYLE = -20; <span style="color:Blue">const</span> <span style="color:Blue">int</span> GWL_STYLE = -16; <span style="color:Blue">const</span> <span style="color:Blue">int</span> GWL_WNDPROC = -4; <span style="color:Blue">const</span> <span style="color:Blue">int</span> GWL_HINSTANCE = -6; <span style="color:Blue">const</span> <span style="color:Blue">int</span> GWL_HWNDPARENT = -8; <span style="color:Blue">const</span> <span style="color:Blue">int</span> GWL_ID = -12; <span style="color:Blue">const</span> <span style="color:Blue">int</span> GWL_USERDATA = -21; <span style="color:Blue">const</span> <span style="color:Blue">int</span> DWL_DLGPROC = 4; <span style="color:Blue">const</span> <span style="color:Blue">int</span> DWL_MSGRESULT = 0; <span style="color:Blue">const</span> <span style="color:Blue">int</span> DWL_USER = 8; <span style="color:Blue">const</span> <span style="color:Blue">short</span> WM_CAP = 0x400; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_SET_CALLBACK_FRAME = WM_CAP + 5; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_DRIVER_CONNECT = WM_CAP + 10; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_DRIVER_DISCONNECT = WM_CAP + 11; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_EDIT_COPY = WM_CAP + 30; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_GET_VIDEOFORMAT = WM_CAP + 44; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_SET_VIDEOFORMAT = WM_CAP + 45; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_SET_PREVIEW = WM_CAP + 50; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_SET_PREVIEWRATE = WM_CAP + 52; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_SET_SCALE = WM_CAP + 53; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_GET_STATUS = WM_CAP + 54; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WM_CAP_GRAB_FRAME = WM_CAP + 60; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WS_CHILD = 0x40000000; <span style="color:Blue">const</span> <span style="color:Blue">int</span> WS_VISIBLE = 0x10000000; <span style="color:Blue">const</span> <span style="color:Blue">short</span> SWP_NOMOVE = 0x2; <span style="color:Blue">const</span> <span style="color:Blue">short</span> SWP_NOSIZE = 1; <span style="color:Blue">const</span> <span style="color:Blue">short</span> SWP_NOZORDER = 0x4; <span style="color:Blue">const</span> <span style="color:Blue">short</span> SWP_FRAMECHANGED = 0x20; <span style="color:Blue">const</span> <span style="color:Blue">short</span> HWND_BOTTOM = 1; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICTYPE_VIDEO = (<span style="color:Blue">int</span>)<span style="color:#A31515">'v'</span> | (<span style="color:Blue">int</span>)<span style="color:#A31515">'i'</span> &lt;&lt; 8 | (<span style="color:Blue">int</span>)<span style="color:#A31515">'d'</span> &lt;&lt; 16 | (<span style="color:Blue">int</span>)<span style="color:#A31515">'c'</span> &lt;&lt; 24; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICMODE_DECOMPRESS = 2; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICMODE_FASTDECOMPRESS = 3; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICMODE_FASTCOMPRESS = 5; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICMODE_DRAW = 8; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICM_GETINFO = 0x4000 + 0x1000 + 2; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICM_DECOMPRESS_GET_FORMAT = 0x4000 + 10; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICM_DECOMPRESS_BEGIN = 0x4000 + 12; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICM_DECOMPRESS = 0x4000 + 13; <span style="color:Blue">const</span> <span style="color:Blue">int</span> ICM_DECOMPRESS_END = 0x4000 + 14; <span style="color:Blue">#endregion</span> <span style="color:Blue">#region</span> PInvokes [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, CharSet = CharSet.Ansi, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">bool</span> SetWindowPos(IntPtr hwnd, IntPtr hWndInsertAfter, <span style="color:Blue">int</span> x, <span style="color:Blue">int</span> y, <span style="color:Blue">int</span> cx, <span style="color:Blue">int</span> cy, <span style="color:Blue">uint</span> wFlags); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, CharSet = CharSet.Ansi, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> SetWindowLong(IntPtr hwnd, <span style="color:Blue">int</span> type, <span style="color:Blue">int</span> value); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, CharSet = CharSet.Ansi, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> GetWindowLong(IntPtr hwnd, <span style="color:Blue">int</span> type); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, CharSet = CharSet.Ansi, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">bool</span> DestroyWindow(IntPtr hwnd); [DllImport(<span style="color:#A31515">&quot;avicap32.dll&quot;</span>, EntryPoint = <span style="color:#A31515">&quot;capCreateCaptureWindowW&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> IntPtr capCreateCaptureWindow(<span style="color:Blue">string</span> lpszWindowName, <span style="color:Blue">int</span> dwStyle, <span style="color:Blue">int</span> x, <span style="color:Blue">int</span> y, <span style="color:Blue">int</span> nWidth, <span style="color:Blue">short</span> nHeight, IntPtr hWndParent, <span style="color:Blue">int</span> nID); [DllImport(<span style="color:#A31515">&quot;avicap32.dll&quot;</span>, EntryPoint = <span style="color:#A31515">&quot;capGetDriverDescriptionW&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">bool</span> capGetDriverDescription(<span style="color:Blue">short</span> wDriver, <span style="color:Blue">string</span> lpszName, <span style="color:Blue">int</span> cbName, <span style="color:Blue">string</span> lpszVer, <span style="color:Blue">int</span> cbVer); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, EntryPoint = <span style="color:#A31515">&quot;SendMessageW&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> SendMessage(IntPtr hwnd, <span style="color:Blue">int</span> wMsg, <span style="color:Blue">int</span> wParam, [MarshalAs(UnmanagedType.AsAny)]<span style="color:Blue">object</span> lParam); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, EntryPoint = <span style="color:#A31515">&quot;SendMessageW&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> SendMessage(IntPtr hwnd, <span style="color:Blue">int</span> wMsg, <span style="color:Blue">int</span> wParam, <span style="color:Blue">ref</span> BITMAPINFO lParam); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, EntryPoint = <span style="color:#A31515">&quot;SendMessageW&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> SendMessage(IntPtr hwnd, <span style="color:Blue">int</span> wMsg, <span style="color:Blue">int</span> wParam, CallbackGetFrame callback); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, EntryPoint = <span style="color:#A31515">&quot;SendMessageW&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> SendMessage(IntPtr hwnd, <span style="color:Blue">int</span> wMsg, <span style="color:Blue">int</span> wParam, <span style="color:Blue">ref</span> CAPSTATE state); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, EntryPoint = <span style="color:#A31515">&quot;SendMessageW&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> SendMessage(IntPtr hwnd, <span style="color:Blue">int</span> wMsg, <span style="color:Blue">ref</span> BITMAPINFO bIn, <span style="color:Blue">ref</span> BITMAPINFO bOut); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, EntryPoint = <span style="color:#A31515">&quot;SendMessageW&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> SendMessage(IntPtr hwnd, <span style="color:Blue">int</span> wMsg, <span style="color:Blue">ref</span> ICINFO bIn, <span style="color:Blue">int</span> size); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> IntPtr SetParent(IntPtr child, IntPtr parent); [DllImport(<span style="color:#A31515">&quot;user32&quot;</span>, CharSet = CharSet.Unicode, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> IntPtr GetParent(IntPtr child); [DllImport(<span style="color:#A31515">&quot;msvfw32.dll&quot;</span>, CharSet = CharSet.Auto, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> IntPtr ICLocate(<span style="color:Blue">int</span> type, <span style="color:Blue">int</span> handler, <span style="color:Blue">ref</span> BITMAPINFO biIn, <span style="color:Blue">ref</span> BITMAPINFO biOut, <span style="color:Blue">short</span> flags); [DllImport(<span style="color:#A31515">&quot;msvfw32.dll&quot;</span>, CharSet = CharSet.Auto, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> IntPtr ICLocate(<span style="color:Blue">int</span> type, <span style="color:Blue">int</span> handler, <span style="color:Blue">ref</span> BITMAPINFO biIn, <span style="color:Blue">int</span> lpBiOut, <span style="color:Blue">short</span> flags); [DllImport(<span style="color:#A31515">&quot;msvfw32.dll&quot;</span>, CharSet = CharSet.Auto, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> IntPtr ICOpen(<span style="color:Blue">int</span> type, <span style="color:Blue">int</span> handler, <span style="color:Blue">uint</span> flags); [DllImport(<span style="color:#A31515">&quot;msvfw32.dll&quot;</span>, CharSet = CharSet.Auto, SetLastError = <span style="color:Blue">true</span>, ExactSpelling = <span style="color:Blue">true</span>)] <span style="color:Blue">static</span> <span style="color:Blue">extern</span> <span style="color:Blue">int</span> ICDecompress(IntPtr dec, <span style="color:Blue">uint</span> flags, <span style="color:Blue">ref</span> BITMAPINFO biIn, IntPtr source, <span style="color:Blue">ref</span> BITMAPINFO biOut, IntPtr target); <span style="color:Blue">#endregion</span> <span style="color:Blue">string</span> name; <span style="color:Blue">string</span> ver; <span style="color:Blue">int</span> id; IntPtr capWnd = IntPtr.Zero; <span style="color:Blue">bool</span> conn = <span style="color:Blue">false</span>; BITMAPINFO binfo; BITMAPINFO biOut; IntPtr dec = IntPtr.Zero; Device(<span style="color:Blue">int</span> i, <span style="color:Blue">string</span> n, <span style="color:Blue">string</span> v) { id = i; name = n; ver = v; } ~Device() { <span style="color:Blue">if</span> (capWnd != IntPtr.Zero) { Disconnect(); } } <span style="color:Blue">void</span> FrameCallback(IntPtr hWnd, <span style="color:Blue">ref</span> VIDEOHDR vhdr) { <span style="color:Blue">if</span> (hWnd == IntPtr.Zero) <span style="color:Blue">return</span>; IntPtr data = vhdr.lpData; <span style="color:Green">//if (binfo.biCompression != 0)</span> <span style="color:Green">//{</span> <span style="color:Green">// data = Marshal.AllocHGlobal(biOut.biSizeImage);</span> <span style="color:Green">// if (ICDecompress(dec, 0x80000000, ref binfo, vhdr.lpData, ref biOut, data) != 0) return;</span> <span style="color:Green">//}</span> Bitmap bmp = <span style="color:Blue">new</span> Bitmap(Width, Height, Width*binfo.biBitCount/8, System.Drawing.Imaging.PixelFormat.Format24bppRgb, data); Callback(bmp); } <span style="color:Blue">public</span> <span style="color:Blue">bool</span> Connect() { capWnd = capCreateCaptureWindow(<span style="color:#A31515">&quot;&quot;</span>, 0, 0, 0, 0, 0, IntPtr.Zero, id); <span style="color:Blue">if</span> (0 == SendMessage(capWnd, WM_CAP_DRIVER_CONNECT, id, 0)) { DestroyWindow(capWnd); <span style="color:Blue">return</span> <span style="color:Blue">false</span>; } binfo = BITMAPINFO.Default; binfo.biWidth = 640; binfo.biHeight = 480; binfo.biSizeImage = binfo.biBitCount * binfo.biWidth * binfo.biHeight / 8; <span style="color:Green">//if(SendMessage(capWnd, WM_CAP_SET_VIDEOFORMAT, 40, ref binfo) == 0) return false; // the webcam doesn't accept the new format</span> SendMessage(capWnd, WM_CAP_GET_VIDEOFORMAT, 40, <span style="color:Blue">ref</span> binfo); <span style="color:Blue">if</span> (binfo.biCompression != 0) { <span style="color:Green">//biOut = BITMAPINFO.Default;</span> <span style="color:Green">//biOut.biWidth = binfo.biWidth;</span> <span style="color:Green">//biOut.biHeight = binfo.biHeight;</span> <span style="color:Green">//biOut.biSizeImage = biOut.biBitCount * binfo.biWidth * binfo.biHeight / 8;</span> biOut = <span style="color:Blue">new</span> BITMAPINFO(); <span style="color:Green">//dec = ICLocate(ICTYPE_VIDEO, binfo.biCompression, ref binfo, 0, ICMODE_DECOMPRESS);</span> dec = ICOpen(ICTYPE_VIDEO, binfo.biCompression, ICMODE_DECOMPRESS); <span style="color:Blue">if</span> (dec == IntPtr.Zero) <span style="color:Blue">return</span> <span style="color:Blue">false</span>; <span style="color:Blue">if</span> (SendMessage(dec, ICM_DECOMPRESS_GET_FORMAT, <span style="color:Blue">ref</span> binfo, <span style="color:Blue">ref</span> biOut) != 0) <span style="color:Green">// should return ICERR_OK that is actually 0</span> <span style="color:Blue">return</span> <span style="color:Blue">false</span>; <span style="color:Green">// nothing is written in &quot;biOut&quot;</span> ICINFO cinf = <span style="color:Blue">new</span> ICINFO(); <span style="color:Blue">int</span> s = SendMessage(dec, ICM_GETINFO, 0, 0); <span style="color:Green">// shoul return size of the data but returns 0</span> SendMessage(dec, ICM_GETINFO, <span style="color:Blue">ref</span> cinf, 296); <span style="color:Green">// after this &quot;cinf&quot; is still empty</span> <span style="color:Blue">if</span> (SendMessage(dec, ICM_DECOMPRESS_BEGIN, <span style="color:Blue">ref</span> binfo, <span style="color:Blue">ref</span> biOut) != 0) <span style="color:Blue">return</span> <span style="color:Blue">false</span>; } SendMessage(capWnd, WM_CAP_SET_PREVIEW, 0, 0); SendMessage(capWnd, WM_CAP_SET_CALLBACK_FRAME, 0, FrameCallback); conn = <span style="color:Blue">true</span>; <span style="color:Blue">return</span> <span style="color:Blue">true</span>; } <span style="color:Blue">public</span> <span style="color:Blue">void</span> Disconnect() { SendMessage(capWnd, WM_CAP_DRIVER_DISCONNECT, id, 0); SendMessage(dec, ICM_DECOMPRESS_END, 0, 0); dec = IntPtr.Zero; DestroyWindow(capWnd); capWnd = IntPtr.Zero; conn = <span style="color:Blue">false</span>; binfo = <span style="color:Blue">new</span> BITMAPINFO(); } <span style="color:Blue">public</span> <span style="color:Blue">void</span> GrabFrame() { SendMessage(capWnd, WM_CAP_GRAB_FRAME, 0, 0); } <span style="color:Blue">public</span> <span style="color:Blue">static</span> Device[] DeviceList { <span style="color:Blue">get</span> { List&lt;Device&gt; list = <span style="color:Blue">new</span> List&lt;Device&gt;(); <span style="color:Blue">string</span> name = <span style="color:Blue">new</span> <span style="color:Blue">string</span>(<span style="color:#A31515">' '</span>, 100); <span style="color:Blue">string</span> ver = <span style="color:Blue">new</span> <span style="color:Blue">string</span>(<span style="color:#A31515">' '</span>, 100); <span style="color:Blue">for</span> (<span style="color:Blue">short</span> i = 0; capGetDriverDescription(i, name, 100, ver, 100); i++) { list.Add(<span style="color:Blue">new</span> Device(i, name.Trim(), ver.Trim())); } <span style="color:Blue">return</span> list.ToArray(); } } <span style="color:Blue">#region</span> Properties <span style="color:Blue">public</span> <span style="color:Blue">string</span> Name { <span style="color:Blue">get</span> { <span style="color:Blue">return</span> name; } } <span style="color:Blue">public</span> <span style="color:Blue">string</span> Version { <span style="color:Blue">get</span> { <span style="color:Blue">return</span> ver; } } <span style="color:Blue">public</span> <span style="color:Blue">int</span> ID { <span style="color:Blue">get</span> { <span style="color:Blue">return</span> id; } } <span style="color:Blue">public</span> <span style="color:Blue">bool</span> IsConnected { <span style="color:Blue">get</span> { <span style="color:Blue">return</span> conn; } } <span style="color:Blue">public</span> IntPtr Handle { <span style="color:Blue">get</span> { <span style="color:Blue">return</span> capWnd; } } <span style="color:Blue">public</span> FrameCallback Callback; <span style="color:Blue">public</span> <span style="color:Blue">int</span> Width { <span style="color:Blue">get</span> { <span style="color:Blue">return</span> binfo.biWidth; } } <span style="color:Blue">public</span> <span style="color:Blue">int</span> Height { <span style="color:Blue">get</span> { <span style="color:Blue">return</span> binfo.biHeight; } } <span style="color:Blue">public</span> IntPtr PreviewParent { <span style="color:Blue">get</span> { <span style="color:Blue">if</span> (capWnd == IntPtr.Zero) <span style="color:Blue">return</span> IntPtr.Zero; <span style="color:Blue">return</span> GetParent(capWnd); } <span style="color:Blue">set</span> { <span style="color:Blue">if</span> (capWnd == IntPtr.Zero) <span style="color:Blue">return</span>; <span style="color:Blue">if</span> (SetParent(capWnd, value) == IntPtr.Zero || value == IntPtr.Zero) { SetWindowPos(capWnd, <span style="color:Blue">new</span> IntPtr(HWND_BOTTOM), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED); } } } <span style="color:Blue">public</span> <span style="color:Blue">bool</span> Preview { <span style="color:Blue">get</span> { CAPSTATE cs = <span style="color:Blue">new</span> CAPSTATE(); <span style="color:Blue">if</span> (SendMessage(capWnd, WM_CAP_GET_STATUS, 76, cs) == 0) <span style="color:Blue">return</span> <span style="color:Blue">false</span>; <span style="color:Blue">else</span> <span style="color:Blue">return</span> cs.fLiveWindow != 0; } <span style="color:Blue">set</span> { SendMessage(capWnd, WM_CAP_SET_PREVIEW, value ? 1 : 0, 0); <span style="color:Blue">if</span> (value) PreviewRate = 66; } } <span style="color:Blue">public</span> <span style="color:Blue">int</span> PreviewRate { <span style="color:Blue">set</span> { SendMessage(capWnd, WM_CAP_SET_PREVIEWRATE, value, 0); } } <span style="color:Blue">#endregion</span> } } </pre> </div> <div>Could anybody help me?</div> Thanks.</div> </div>Thu, 19 Nov 2009 16:44:20 Z2009-11-30T10:18:00Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/13045dff-8480-4b8c-877b-bd508c1a76a5http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/13045dff-8480-4b8c-877b-bd508c1a76a5RobbKirkhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=RobbKirkWebBrowserHi to everyone, <div><br/></div> <div>When I use WebBrowser control'method public void Navigate(string urlString, string targetFrameName, byte[] postData, string additionalHeaders);</div> <div><br/></div> <div>it always takes more and more memory.</div> <div><br/></div> <div>I'm calling it in timely manner, every minute.</div> <div><br/></div> <div>Is it possible to avoid memory leak?</div> <div><br/></div> <div>Seems like it keeps all data and doesn't release it after navigation.</div> <div><br/></div> <div>I tried calling GC without success.</div> <div><br/></div> <div>Any idea, please?</div>Mon, 30 Nov 2009 10:16:32 Z2009-11-30T10:16:33Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/2a3308db-0d3e-415a-a4f2-a00aca78e1echttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/2a3308db-0d3e-415a-a4f2-a00aca78e1eciHandlerhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=iHandlerC# - How to make a Button with a DropDown Menu?<p>I would like to have a Button with a drop down menu and then when I click on the &quot;menu item&quot;, I will do something.<br/><br/>However, I have no idea how I can &quot;trigger&quot; the even created by Menu Item, I can only do this, as below...<br/><br/>        private void button1_Click(object sender, EventArgs e)<br/>        {<br/>            ContextMenu cm = new ContextMenu();<br/>            cm.MenuItems.Add(&quot;menuItem 1&quot;);<br/>            cm.MenuItems.Add(&quot;menuItem 2&quot;);</p> <p>            cm.Show(button1, new Point(0, button1.Height));<br/>        }<br/><br/><br/>So, may I know how I can do this?  Please help <br/> </p>Thu, 26 Nov 2009 10:28:23 Z2009-11-30T10:03:25Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/aa21a068-43a3-4306-b218-d95b23da76fchttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/aa21a068-43a3-4306-b218-d95b23da76fcinvader7http://social.msdn.microsoft.com/Profile/pt-BR/?user=invader7Dir list box...Hello every body, i have a dir list box in my form and i give it as path a network path, when i run the form it lists me the contents of the path correctly. i want to know if i can hide from dir list box the base path or if i can rename it, i don't want to see \\server\share i want to see the work &quot;base path&quot; for example !Wed, 25 Nov 2009 18:04:43 Z2009-11-30T09:39:53Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/5827ad9d-2c2a-48f7-a943-2302ce07e2a8http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/5827ad9d-2c2a-48f7-a943-2302ce07e2a8nemesiscsharphttp://social.msdn.microsoft.com/Profile/pt-BR/?user=nemesiscsharpDo someone know how to auto-filter SEARCH from my datagridview using mysql connections?kindly help me again sir. :) Thanks<br/>Mon, 30 Nov 2009 06:42:36 Z2009-11-30T09:17:04Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/8bf25bb5-f745-42b1-b29f-06d3f231636bhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/8bf25bb5-f745-42b1-b29f-06d3f231636bfathatsmehttp://social.msdn.microsoft.com/Profile/pt-BR/?user=fathatsmehow to connect mysql remote database to my c# application?<span style="font-family:Arial;font-size:13px;white-space:pre">how to connect mysql remote database to my c# application?</span> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre">connectionstrings.com does not have code for this.</span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div>Mon, 30 Nov 2009 08:55:28 Z2009-11-30T09:04:04Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/128aa763-2c40-4eb5-b253-5d7cab0b93a4http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/128aa763-2c40-4eb5-b253-5d7cab0b93a4hazzhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=hazzA socket is disposed of in a Timeout and I get an error in ReceiveCallBack() trying to access..<p>Hightlighted in large purple font below are the two lines where the following errors occur and this order;<br/>1.    int bytesRead = client.EndReceive(ar);         in ReceiveCallBack()  and<br/>2.    client.Shutdown(SocketShutdown.Both);       in DeviceCommunicationTimeOut</p> <p><br/>I can see that the TimeOut, after 125 milliseconds, is closing the socket and then when there is an  unsuccessful attempt to access the socket in the ReceiveCallBack().  But I haven't figured out how to prevent that. Thank you so much for any help on my first asynchronous socket app.</p> <div style="color:black;background-color:white"> <div style="color:black;background-color:white"> <div style="color:black;background-color:white"> <pre><span style="color:blue">public</span> <span style="color:blue">class</span> StateObject { <span style="color:blue">public</span> Socket workSocket = <span style="color:blue">null</span>; <span style="color:blue">public</span> <span style="color:blue">const</span> <span style="color:blue">int</span> BufferSizeForReceive = 2400; <span style="color:blue">public</span> <span style="color:blue">byte</span>[] buffer = <span style="color:blue">new</span> <span style="color:blue">byte</span>[BufferSizeForReceive]; <span style="color:blue">public</span> StringBuilder sb = <span style="color:blue">new</span> StringBuilder(); <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">byte</span>[] toSocket; } <span style="color:blue">public</span> <span style="color:blue">partial</span> <span style="color:blue">class</span> Form1 : Form { <span style="color:blue">private</span> <span style="color:blue">static</span> System.Threading.Timer timerForTimeOut = <span style="color:blue">null</span>; <span style="color:green">//one shot </span> <span style="color:blue">private</span> <span style="color:blue">static</span> Object syncObj = <span style="color:blue">new</span> Object(); <span style="color:green">//Lock when receiving data or TimeOut called</span> <span style="color:blue">private</span> <span style="color:blue">static</span> ManualResetEvent connectDone = <span style="color:blue">new</span> ManualResetEvent(<span style="color:blue">false</span>); <span style="color:green">//??</span> <span style="color:blue">private</span> <span style="color:blue">static</span> ManualResetEvent receiveDone = <span style="color:blue">new</span> ManualResetEvent(<span style="color:blue">false</span>); <span style="color:green">//??</span> <span style="color:blue">private</span> <span style="color:blue">static</span> ManualResetEvent sendDone = <span style="color:blue">new</span> ManualResetEvent(<span style="color:blue">false</span>); <span style="color:green">//??</span> <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">byte</span>[] toSocket; <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">string</span> response; <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">string</span> softwareVersionFromDevice; <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">string</span> host = <span style="color:#a31515">&quot;10.0.110.35&quot;</span>; <span style="color:blue">private</span> <span style="color:blue">static</span> Int32 port = 50000; <span style="color:blue">public</span> Form1() { InitializeComponent(); toSocket = <span style="color:blue">new</span> <span style="color:blue">byte</span>[7]; toSocket[0] = 2; <span style="color:green">//msgID</span> toSocket[1] = 0; <span style="color:green">//status</span> toSocket[2] = 0; <span style="color:green">//data lehgth</span> toSocket[3] = 0; toSocket[4] = 0; <span style="color:green">//seq #</span> toSocket[5] = 1; } <span style="color:blue">private</span> <span style="color:blue">void</span> button1_Click(<span style="color:blue">object</span> sender, EventArgs e) { BeginConnect(host, port); } <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">void</span> BeginConnect(<span style="color:blue">string</span> host, <span style="color:blue">int</span> port) { <span style="color:blue">try</span> { Socket s = <span style="color:blue">new</span> Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); connectDone.Reset(); s.BeginConnect(host, port, <span style="color:blue">new</span> AsyncCallback(ConnectCallback), s); connectDone.WaitOne(); } <span style="color:blue">catch</span> (Exception ex) { Console.Write(<span style="color:#a31515">&quot;BeginConnect exception = &quot;</span> + ex.ToString()); } } <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">void</span> ConnectCallback(IAsyncResult ar) { <span style="color:blue">try</span> { Socket client = (Socket)ar.AsyncState; client.EndConnect(ar); connectDone.Set(); <span style="color:green">// create a one-shot timer</span> <span style="color:blue">if</span> (timerForTimeOut == <span style="color:blue">null</span>) timerForTimeOut = <span style="color:blue">new</span> System.Threading.Timer(DeviceCommunicationTimeOut, client, 125, 125); Send(client); } <span style="color:blue">catch</span> (Exception ex) { Console.Write(<span style="color:#a31515">&quot;ConnectCallback exception = &quot;</span> + ex.ToString()); } } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> DeviceCommunicationTimeOut(<span style="color:blue">object</span> state) { <span style="color:blue">try</span> { Socket client = (Socket)state; <span style="color:blue">lock</span> (syncObj) { <span style="color:green">// timed out. close and shutdown socket</span> <span style="font-size:medium;color:#800080"> client.Shutdown(SocketShutdown.Both); </span> client.Close(); } } <span style="color:blue">catch</span> (Exception ex) { Console.Write(<span style="color:#a31515">&quot;DeviceCommunicationTimeOut exception = &quot;</span> + ex.ToString()); } } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> Send(Socket client) { <span style="color:blue">try</span> { client.BeginSend(toSocket, 0, toSocket.Length, SocketFlags.None, <span style="color:blue">new</span> AsyncCallback(SendCallback), client); } <span style="color:blue">catch</span> (Exception ex) { Console.Write(<span style="color:#a31515">&quot;Send exception = &quot;</span> + ex.ToString()); } } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> SendCallback(IAsyncResult ar) { Socket client = (Socket)ar.AsyncState; <span style="color:blue">int</span> bytesSent = client.EndSend(ar); sendDone.Set(); Receive(client); } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> Receive(Socket client) { <span style="color:blue">try</span> { StateObject state = <span style="color:blue">new</span> StateObject(); state.workSocket = client; client.BeginReceive(state.buffer, 0, StateObject.BufferSizeForReceive, 0, <span style="color:blue">new</span> AsyncCallback(ReceiveCallback), state); } <span style="color:blue">catch</span> (Exception ex) { Console.Write(<span style="color:#a31515">&quot;Receive exception = &quot;</span> + ex.ToString()); } } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> ReceiveCallback(IAsyncResult ar) { <span style="color:blue">try</span> { <span style="color:blue">lock</span> (syncObj) { timerForTimeOut.Change(125, 10000); <span style="color:green">// Timeout.Infinite</span> } StateObject state = (StateObject)ar.AsyncState; Socket client = state.workSocket; <span style="color:blue">int</span> <span style="font-size:medium;color:#800080"> bytesRead = client.EndReceive(ar); </span> <span style="color:blue">if</span> (bytesRead &gt; 0) { state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); client.BeginReceive(state.buffer, 0, StateObject.BufferSizeForReceive, 0, <span style="color:blue">new</span> AsyncCallback(ReceiveCallback), state); } <span style="color:blue">else</span> { <span style="color:blue">if</span> (state.sb.Length &gt; 1) { response = state.sb.ToString(); } receiveDone.Set(); } } <span style="color:blue">catch</span> (ObjectDisposedException ex) { Console.WriteLine(<span style="color:#a31515">&quot;EndReceive exception = &quot;</span> + ex.ToString()); } } } </pre> </div> </div> </div>Mon, 23 Nov 2009 21:55:26 Z2009-11-30T08:59:07Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/41508772-2e9f-4254-a15c-816f933a9378http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/41508772-2e9f-4254-a15c-816f933a9378Anish MCAhttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Anish%20MCACode for a Class file in C# Can anyone help me plz<br/> I want a complete sample of class file through which we can establish an SQL Connection and which include certain important method which is reusable.(Like dataset,datatable,insert etc)..<br/> I mean a common class file for my entire application.<br/> It is for Windows application ,c# and SQL Server2000.<br/> If any one share the code ,it will be very helpfull<br/> Plz reply<br/> Iam waiting<br/> Its urgent<br/> Thanks a lot<hr class="sig">http://dotnetsourcecodes.blogspot.com/Mon, 30 Nov 2009 08:31:17 Z2009-11-30T08:34:29Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/8b147f5c-6f6a-47ad-bbce-f53300024448http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/8b147f5c-6f6a-47ad-bbce-f53300024448BA_Newbiehttp://social.msdn.microsoft.com/Profile/pt-BR/?user=BA_NewbieRegex for ASCII with exceptionsHi All, <br/> <br/> I have been trying to find the correct REGEX expression, but in vain. Hope the experts here can help me further..<br/> <br/> I have a string which must be either visible ASCII characters (from 0x20 to 0x7E), but <strong>may</strong> contain a 0x00.<br/> <br/> I tried something on the lines of:<br/> <br/> <pre lang="x-c#">Regex rx = new Regex(&quot;[:print:]|\x00&quot;); if (rx.IsMatch(myASCIIString)) { //Show }</pre> But it doesnt work! Any suggestions??<br/> <br/> Examples of my string can be: <br/> <br/> 1E<strong>3132</strong> 7F  - should fail, it has non-visisble ASCII like 0x1D and 0x7F<br/> <strong>342033</strong> 00  - should pass, has ASCII and also 0x00.<br/> <strong>32314145</strong> - should pass, it has only visible ASCII!<br/> <br/> <br/> Thank u all!!<hr class="sig">If the reply answers your question, please mark it as Answer, or Helpful, if it helped! Thanks!Fri, 27 Nov 2009 11:03:17 Z2009-11-30T08:26:35Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/d511f625-f0eb-46c6-8b41-5e8cb5ef2ed0http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/d511f625-f0eb-46c6-8b41-5e8cb5ef2ed0vipinbakayahttp://social.msdn.microsoft.com/Profile/pt-BR/?user=vipinbakayahow to atart with c#how to write code in c#Sat, 28 Nov 2009 12:35:16 Z2009-11-30T08:26:32Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/fc409935-0f87-4889-9c0b-f542fdcb8e2ahttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/fc409935-0f87-4889-9c0b-f542fdcb8e2aRoberto Salvahttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Roberto%20SalvaSome help on a threading model, I am using a timer but it does not work, somewhat a newbie questionHi. <div><br/></div> <div>I am moving part of a software I have on other languages to C#, basically I am working with a HID device ( I can open it, read it, see if it's attached, set features etc ) </div> <div><br/></div> <div>but I have a small problem, since I am not that well aquainted with C# I am using a timer:</div> <div><br/></div> <div> <div>Timer tmr = new Timer();</div> <div>tmr.Tick += new EventHandler(tmr_Tick);</div> <div>tmr.Interval = 50;</div> <div><br/></div> <div>Then inside the timer I am reading the HID device, the problem is that I need somewhat realtime</div> <div>information from the device, but with the timer it just stalls and stall, actually if I set it to 50ms.</div> <div>the application &quot;dies&quot; waiting for the information.</div> <div><br/></div> <div>I know I have to make a thread to read the data, but I am quite confused on what type of thread to use.</div> <div><br/></div> <div>I don't mind if for instance a &quot;sample&quot; gets lost, but I need to read the information well as I said before in realtime.</div> <div><br/></div> <div>so right now I have a function:</div> <div><br/></div> <div><br/></div> <div> <div> void tmr_Tick(object sender, EventArgs e)</div> <div>        {</div> <div>         </div> <div>            readbuffer = readHID();</div> <div>            /** more code after this **/</div> <div>         }</div> <div><br/></div> <div>ReadHid is:</div> <div><br/></div> <div> public byte[] readHid() </div> <div>{</div> <div>///// Some code ////////</div> <div>///core:</div> <div><br/></div> <div>success = FileIO.ReadFile(readHandle, bufferPtr, bufferLength, ref bytesRead, IntPtr.Zero);</div> <div><br/></div> <div> <div> Marshal.Copy(bufferPtr, readbuffer, 0, bytesRead);</div> <div> Marshal.FreeHGlobal(bufferPtr);</div> <div> return readbuffer;</div> </div> <div><br/></div> <div><br/></div> <div>}</div> <div><br/></div> <div>so it returns the byte[] filled with data and then I process the data.</div> <div><br/></div> <div>but this kills the program excecution.</div> <div><br/></div> <div><br/></div> <div>can someone help me with this... silly thing. :/ </div> <div><br/></div> <div>Thank you in advance</div> </div> </div>Mon, 30 Nov 2009 07:01:22 Z2009-11-30T08:16:10Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/3bdfc0d8-20fd-4d75-8d2e-38a8c94755d9http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/3bdfc0d8-20fd-4d75-8d2e-38a8c94755d9knjihttp://social.msdn.microsoft.com/Profile/pt-BR/?user=knjiUsing using System.Runtime.InteropServices.ProgIdAttribute<span style="font-size:x-small"><span style="font-size:x-small"> <p>I have a class decorated with:<br/><br/>[</p> </span></span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">ProgId</span></span><span style="font-size:x-small">(</span><span style="font-size:x-small;color:#a31515"><span style="font-size:x-small;color:#a31515">&quot;Category.Class1&quot;</span></span><span style="font-size:x-small">)]<br/><br/>But when I do:<br/><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af"><br/>Type</span></span><span style="font-size:x-small"> t = </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">Type</span></span><span style="font-size:x-small">.GetTypeFromProgID(</span><span style="font-size:x-small;color:#a31515"><span style="font-size:x-small;color:#a31515">&quot;Category.Class1&quot;<span style="font-size:x-small;color:#000000">)<br/></span></span></span><span style="font-size:x-small"><br/>I get null for t.  What am I missing here?<br/>TIA.<br/></span></span>Mon, 30 Nov 2009 04:28:58 Z2009-11-30T08:14:59Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/bd4fdf51-0962-45f4-8f6d-f45a32714e17http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/bd4fdf51-0962-45f4-8f6d-f45a32714e17Scorgihttp://social.msdn.microsoft.com/Profile/pt-BR/?user=Scorgitwo different values to imagecolumn in gridview<p>I have a gridview with an imagecolumn. This column should be able to take two different values from a plc. <br/><br/>One bool value, where the value 0 or 1 should return an image. <br/><br/>One dint value, where the value should actually be shown in the gridview. <br/><br/>How can this be accomplished taken into account that a dint value can also be 0 and 1. I must be able to check on the type bool or dint. Hope anybody can help.</p>Mon, 30 Nov 2009 08:03:41 Z2009-11-30T08:03:42Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/acb94175-b0c8-477b-84c4-47e5f239041fhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/acb94175-b0c8-477b-84c4-47e5f239041fPolythemehttp://social.msdn.microsoft.com/Profile/pt-BR/?user=PolythemeCollection of another collection<p>I need to create a List&lt;KeyValuePair&lt;int,int&gt;&gt; collection. But Fxcop thinks that containing a collection inside another collection is not a good practice.However, defining a class for the KeyValuePair&lt;int,int&gt; sounds strange as well. Doyou have any suggestion about this structure?</p>Mon, 30 Nov 2009 03:24:14 Z2009-11-30T07:59:19Zhttp://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/b0d45d3b-e364-4166-8cf1-2534ef66ccb0http://social.msdn.microsoft.com/Forums/pt-BR/csharpgeneral/thread/b0d45d3b-e364-4166-8cf1-2534ef66ccb0MDMourahttp://social.msdn.microsoft.com/Profile/pt-BR/?user=MDMouraBase64 and Byte ConversionHello,<br/> <br/> I have the following:<br/> String result = Convert.ToBase64String(Encoding.UTF8.GetBytes(&quot;Test&quot;));<br/> <br/> Shouldn't result become &quot;Test&quot;? I get &quot;VGVzdA==&quot;<br/> <br/> I am using this approach to save Byte data into a XML file and get it back to a string.<br/> It isn't working so I made this test and I was expecting to get &quot;Test&quot; in result.<br/> <br/> Thanks,<br/> Miguel<br/>Sat, 28 Nov 2009 02:11:44 Z2009-11-30T07:52:15Z