c#-2.0

How to resolve the winforms error “A generic error occurred in GDI+. ”?

梦想的初衷 提交于 2019-12-07 08:44:13
问题 I am facing the following exception in my C#.net win forms application. A generic error occurred in GDI+. at System.Drawing.Graphics.CheckErrorStatus(Int32 status) at System.Drawing.Graphics.DrawRectangle(Pen pen, Int32 x, Int32 y, Int32 width, Int32 height) at WeifenLuo.WinFormsUI.Docking.DockWindow.OnPaint(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at

Web service variable shared for the lifetime of the webservice?

 ̄綄美尐妖づ 提交于 2019-12-07 08:24:03
问题 How can I make a variable (object) available for the whole lifetime of the webservice? Static variable seem to work but is there an other way to do it? 回答1: Static variables exist for the lifetime of the App Domain that contains them. In the case of a web service, this is usually the ASP.Net Worker Process. What that means is that when IIS decides to cycle the worker process, your static variable will be gone. This may be what you want, in which case it is probably a good choice. (Putting

Getting a StringCollection out of AppSettings through the configuration manager

大憨熊 提交于 2019-12-07 06:13:53
问题 I am accessing my assembly's configuration like this: ExeConfigurationFileMap map = new ExeConfigurationFileMap(); map.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + ".config"; Configuration conf = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); AppSettingsSection appSettings = conf.AppSettings; My .config file contains a section like this <configSections> <sectionGroup name="applicationSettings" type="System.Configuration

How to select nodes where node name contains “mystring”

久未见 提交于 2019-12-07 03:24:16
问题 I need to get XmlNodeList where node name contains "mystring" XML <?xml version="1.0" encoding="utf-8"?> <root> <node1> node1 value </node1> <node2_mystring> node2 value </node2_mystring> <node3> node3 value </node3> <node4_mystring> node 4 value </node4_mystring> </root> Desired output is <?xml version="1.0" encoding="utf-8"?> <root> <node2_mystring> node2 value </node2_mystring> <node4_mystring> node 4 value </node4_mystring> </root> I tried something like XmlNodeList mystringElements =

.Net dll reference - deployment onto PCs with different versions of 3rd party dll

限于喜欢 提交于 2019-12-06 16:13:09
Could you tell me the best approach for this scenario. I have inherited a new project and have not come across this scenario before. We have a reference in our C# Windows Forms application to a 3rd party tool for producing documents. There are two different versions of the 3rd party tool in the deployment environment installed on people's PCs - v1.0 and v2.0. I can only build our Windows Forms application to work with either v1.0 or v2.0 of the 3rd party tool. To do so I have to install either version on my development PC before building. This is obviously a bad approach as I have to uninstall

what's the advantage of Property Info?

给你一囗甜甜゛ 提交于 2019-12-06 12:09:56
问题 In .net FrameWork 3.5 we can get the Property Information using below mentioned code. using System; using System.Linq.Expressions; using System.Reflection; class Foo { public string Bar { get; set; } } static class Program { static void Main() { PropertyInfo prop = PropertyHelper<Foo>.GetProperty(x => x.Bar); } } public static class PropertyHelper<T> { public static PropertyInfo GetProperty<TValue>( Expression<Func<T, TValue>> selector) { Expression body = selector; if (body is

Process.WaitForExit not waiting

℡╲_俬逩灬. 提交于 2019-12-06 11:07:30
I have the following code and the WaitForExit method is not waiting. It just runs the command and moves on to the next statement. The command is to unintall an application and the parms are for the uninstall command. The uninstall runs fine but I need the uninstall to finish before moving on...it's not blocking. ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = commandName; startInfo.Arguments = parms; Process process = Process.Start(startInfo); process.WaitForExit(); I strongly suspect that Andrey's comment is right - the process you're starting is exiting, but having

What's the fastest way to ReadProcessMemory?

江枫思渺然 提交于 2019-12-06 09:47:34
I'm trying to search for all instances of a null-terminated string the memory of a process. I enumed all the alloced memory areas with VirtualQueryEx, then I read them with ReadProcessMemory to a byte array and search using this algo (which I found here and the author claims to be the fastest) public static unsafe List<long> IndexesOf(byte[] Haystack, byte[] Needle) { List<long> Indexes = new List<long>(); fixed (byte* H = Haystack) fixed (byte* N = Needle) { long i = 0; for (byte* hNext = H, hEnd = H + Haystack.LongLength; hNext < hEnd; i++, hNext++) { bool Found = true; for (byte* hInc =

.net - Glass effect in C# 2.0 applications

时光总嘲笑我的痴心妄想 提交于 2019-12-06 09:25:13
问题 How can I give a Vista or Mac OS X style glass effects on windows forms applications in .net 2.0? 回答1: This is done using interop with the Vista DWM (Desktop Window Manager) API. For example, import these functions: [DllImport("dwmapi.dll")] static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins); [StructLayout(LayoutKind.Sequential)] struct Margins { public int cxLeftWidth; public int cxRightWidth; public int cyTopHeight; public int cyBottomHeight; } Then you can

How to reference a field by reflection

 ̄綄美尐妖づ 提交于 2019-12-06 09:20:15
Sorry for the title, it's not explicit. Further to my precedent question , I want to subscribe a method to an event object retrieved dynamically (via reflection). The object in question is a field of a Control : public void SubscribeEvents(Control control) { Type controlType = control.GetType(); FieldInfo[] fields = controlType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo method = typeof(Trace).GetMethod("WriteTrace"); // "button1" hardcoded for the sample FieldInfo f = controlType.GetField("button1", BindingFlags.Public | BindingFlags.NonPublic |