.net

Google Maps-Like Scrolling Panel in WPF

I have a Canvas where I'm drawing a bunch of shapes and other UI elements. This canvas can be very large so I want to put this in a panel which allows me to zoom in/out using the mouse and scroll by dragging the mouse, just like Google Maps. The closest thing I could find was the ScrollViewer but obviously this isn't close enough. Has...

Is it possible to implement a COM interface with a .NET generics class?

I have the following interface which I'm trying to make COM-visible. When I try to generate the type-library it doesn't like the fact that my implementation class derives from a generic-class. Is it possible to use a generic class as a COM implementation class? (I know I could write a non-generic wrapper and export that to COM, but th...

Checking for duplicates in a collection

Suppose you have a collection of classes: class Foo { public string Bar; public string Baz; } List<Foo> foolist; And you want to check this collection to see if another entry has a matching Bar. bool isDuplicate = false; foreach (Foo f in foolist) { if (f.Bar == SomeBar) { isDuplicate = true; brea...

Finalizer launched while its object was still being used

Summary: C#/.NET is supposed to be garbage collected. C# has a destructor, used to clean resources. What happen when an object A is garbage collected the same line I try to clone one of its variable members? Apparently, on multiprocessors, sometimes, the garbage collector wins... The problem Today, on a training session on C#, the teac...

Problem encrypting membership element in web.config

I am trying to encrypt the "system.web.membership" element within the Web.Config of our .Net application to secure username and password to Active Directory. I am using the aspnet_regiis command to encrypt, and have tried several different strings for the value of the "pe" option with no success. I have successfully encrypted the "connec...

Catching exceptions as expected program execution flow control?

I always felt that expecting exceptions to be thrown on a regular basis and using them as flow logic was a bad thing. Exceptions feel like they should be, well, the "exception". If you're expecting and planning for an exception, that would seem to indicate that your code should be refactored, at least in .NET... However. A recent scen...

Enforcing a strict timeout policy on a server side webrequest

We will need to call out to a 3rd party to retrieve a value using REST, however if we do not receive a response within 10ms, I want to use a default value and continue processing. I'm leaning towards using an asynchronous WebRequest do to this, but I was wondering if there was a trick to doing it using a synchronous request. Any advice...

How do I find the number of references that exist for a particular object?

I have a bit of code that passes around a ton of objects and I want to determine if there are any references still lingering around that I am unaware of and where it is those references are located. Any idea of how I can do this? My understanding is that the watch window only allows me to see items available to the currently executing ...

Best way to check if server is reachable in .NET?

I have created a timeclock application in C# that connects to a web service on our server in order to clock employees in/out. The application resides in the system tray and clocks users out if they shut down/suspend their machines or if they are idle for more than three hours to which it clocks them out at the time of last activity. My ...

How to prevent blank xmlns attributes in output from .NET's XmlDocument?

When generating XML from XmlDocument in .NET, a blank xmlns attribute appears the first time an element without an associated namespace is inserted; how can this be prevented? Example: XmlDocument xml = new XmlDocument(); xml.AppendChild(xml.CreateElement("root", "whatever:name-space-1.0")); xml.DocumentElement.AppendChild(xml.Crea...

How can you make a DataGridView scroll one item at a time using the mouse wheel?

We'd like to override DataGridView's default behavior when using a mouse wheel with this control. By default, the DataGridView scrolls a number of rows equal the SystemInformation.MouseWheelScrollLines setting. What we'd like to do is scroll just one item at a time. (We display images in the DataGridView, which are somewhat large. ...

How can I use an event to cause a method to run?

So in my documentation it says: "C# public event TreeViewPlusNodeCheckedEventHandler NodeChecked() You can use this event to run cause a method to run whenever the check-box for a node is checked on the tree." So how do I add a method to my code behind file that will run when a node is checked? The method I want to run is: protected...

Passing a ref or pointer to a managed type as an argument in C++.net

I'm really baffled by this - I know how to do this in VB, unmanaged C++ and C# but for some reason I can't accept a ref variable of a managed type in C++. I'm sure there's a simple answer, really - but here's the C# equivalent: myClass.myFunction(ref variableChangedByfunction); I've tried C++ pointers - no dice. I've tried ref keywords...

What's the best way to remove <br> tags from the end of a string?

The .NET web system I'm working on allows the end user to input HTML formatted text in some situations. In some of those places, we want to leave all the tags, but strip off any trailing break tags (but leave any breaks inside the body of the text.) What's the best way to do this? (I can think of ways to do this, but I'm sure they're ...

Difference between ref and out parameters in .NET

What is the difference between ref and out parameters in .NET? What are the situations where one can be more useful than the other? Can anybody illustrate with a code snippet where one can be used and another can't? ...

Do you use a code profiler?

Do you use a code profiler? if so, Why? What's your favorite? If not, is there a particular reason you don't? ...

How do I use reflection to invoke a private method in C#?

There are a group of private methods in my class, and I need to call one dynamically based on an input value. Both the invoking code and the target methods are in the same instance. The code looks like this: MethodInfo dynMethod = this.GetType().GetMethod("Draw_" + itemType); dynMethod.Invoke(this, new object[] { methodParams }); In t...

How can I detect if there is a floppy in a drive?

I tried to use DriveInfo.IsReady, but it returns false if an unformatted floppy is in the drive. ...

Structure of projects in version control - .NET specific

This post is similar to this previously asked question. I really want to set up my SVN repository in TTB format, but when creating a project in Visual Studio 2008 (ASP.NET/VB.NET), the structure created tends to be incompatible when considering the solution file, project files, folders for projects, multiple projects within solutions, e...

Best place for NHibernate documentation?

I've been looking for good documentation for nhibernate, specifically version 2.0. I've recently returned to .NET development and for the life of me, I can't find the right sort of documentation (or even the most recent). Any suggestions would be greatly appreciated. ...