c#-2.0

Restrict multiple instances of an application

和自甴很熟 提交于 2019-12-02 23:34:54
Okay, so i've created my c# application, created an installer for it and have it working installed on my machine. The problem is, when the user opens the application exe twice, there will be two instances of the application running. I only ever want one instance of the application to be running at any time, how do I go about doing this? Thanks for your help, The common technique for this is to create a named Mutex and check for its presence on application start. See this or this . Code from DDJ: class App : Form { Mutex mutex; App() { Text = "Single Instance!"; mutex = new Mutex(false, "SINGLE

Get Max value from List<myType>

折月煮酒 提交于 2019-12-02 23:15:21
I have List List<MyType> , my type contains Age and RandomID Now I want to find the maximum age from this list. What is the simplest and most efficient way? Jon Skeet Okay, so if you don't have LINQ, you could hard-code it: public int FindMaxAge(List<MyType> list) { if (list.Count == 0) { throw new InvalidOperationException("Empty list"); } int maxAge = int.MinValue; foreach (MyType type in list) { if (type.Age > maxAge) { maxAge = type.Age; } } return maxAge; } Or you could write a more general version, reusable across lots of list types: public int FindMaxValue<T>(List<T> list, Converter<T,

Detecting registry virtualization

痴心易碎 提交于 2019-12-02 19:05:26
I have a set of C# (v2) apps and I am struggling with registry virtualization in Win7 (and to a lesser extent Vista). I have a shared registry configuration area that my applications need to access in HKLM\Software\Company... Prior to Vista, everything was just written to and read from that location as needed. The code appropriately detected failures to write to that registry key and would fall back appropriately (writing to HKCU instead and notifying the user that the settings they had applied would only affect the current user). In Vista, registry virtualization broke all of this because the

What are the predominant .NET 3.0 mocking frameworks?

旧街凉风 提交于 2019-12-02 19:01:33
问题 To preface this, I love Moq. I wish I could use it in .NET 3.0. Sadly, however, I cannot, but I would still like to use mocks for unit testing purposes. Also, I've used Rhino before, but I absolutely hate it. To be a little more descriptive, though, it's because the interface feels clunky and unintuitive--which can be dealt with--and the documentation is either horrible or non-existent--which can't. The essence of my question is whether there are other decently-documented, intuitive, fluent

How can I convert List<string> to List<myEnumType>?

折月煮酒 提交于 2019-12-02 18:24:07
I failed to convert List<string> to List<myEnumType> . I don't know why? string Val = it.Current.Value.ToString(); // works well here List<myEnumType> ValList = new List<myEnumType>(Val.Split(',')); // compile failed Of cause myEnumType type defined as string enum type as this, public enum myEnumType { strVal_1, strVal_2, strVal_3, } Is there anything wrong? Appreciated for you replies. EDIT: Oops, I missed the C# 2 tag as well. I'll leave the other options available below, but: In C# 2, you're probably best using List<T>.ConvertAll : List<MyEnumType> enumList = stringList.ConvertAll(delegate

How to compress files

早过忘川 提交于 2019-12-02 18:22:23
I want to compress a file and a directory in C#. I found some solution in Internet but they are so complex and I couldn't run them in my project. Can anybody suggest me a clear and effective solution? You could use GZipStream in the System.IO.Compression namespace .NET 2.0. public static void CompressFile(string path) { FileStream sourceFile = File.OpenRead(path); FileStream destinationFile = File.Create(path + ".gz"); byte[] buffer = new byte[sourceFile.Length]; sourceFile.Read(buffer, 0, buffer.Length); using (GZipStream output = new GZipStream(destinationFile, CompressionMode.Compress)) {

A simple event bus for .NET [closed]

↘锁芯ラ 提交于 2019-12-02 17:41:55
I want to make a very simple event bus which will allow any client to subscribe to a particular type of event and when any publisher pushes an event on the bus using EventBus.PushEvent() method only the clients that subscribed to that particular event type will get the event. I am using C# and .NET 2.0. Tiny Messenger is a good choice, I've been using it in a live project for 2.5 years now. Some code examples from the Wiki (link below): Publishing messageHub.Publish(new MyMessage()); Subscribing messageHub.Subscribe<MyMessage>((m) => { MessageBox.Show("Message Received!"); }); messageHub

How to launch video icon in camera

允我心安 提交于 2019-12-02 13:48:20
问题 I am trying to launch an app through adb in my android phone. I have tried adb getevent . But it dumps so many events. How can I make out which one I need? Is there any other way I can launch the app? I am looking to launch the video portion of the camera. I was able to launch camera thru adb as: am start -a android.intent.action.MAIN -n com.android.camera/.CameraEntry . The camcorder icon is next to snap icon in camera. I was able to control snap icon through `input keyevent 23. But unable

how to compare two dates in datetimepicker

两盒软妹~` 提交于 2019-12-02 12:54:51
问题 I am doing Windows project, in which I have two DateTimePicker controls, one for StartDate and other for EndDate. In runtime, when user selects the StartDate and EndDate from that controls, it should read the textfile(i.e) log.txt & search line by line get the matching of both these dates and as well as in between dates and write the data to a textbox or label control for eg in log file, data is like below: 3/12/2013 2:51:47 PM - ASDASDASD.D20131203145019 4/12/2013 2:52:23 PM - ASDDFSDSA

Taking a screenshot using c# with out including task bar.

↘锁芯ラ 提交于 2019-12-02 12:21:31
问题 How to take screenshot using c# with out including task bar.I tried some codes but it takes whole screen. 回答1: try with Screen.PrimaryScreen.WorkingArea it gives you the screen excluding task bar Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height, PixelFormat.Format32bppArgb); Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot); gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.WorkingArea.X, Screen.PrimaryScreen