.net

Implementing all portscanning techniques in C# / Creating raw low level packets in C#

I am trying to write a port scanner in C#. I did some research on port scanning methods. If you are interested, these are the links I found useful: http://www.cs.wright.edu/~pmateti/InternetSecurity/Lectures/Probing/index.html ^PPT Presentation^ http://www.auditmypc.com/freescan/readingroom/port_scanning.asp (old) NMAP ...

Enumerating a collection, then modifying it, what is the precedent for throwing an exception?

When enumerating a .NET collection, MSDN states that: An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and its behavior is undefined. What exactly does "irrecoverably invalidate...

ComboBox.SelectedValue does not match displayed text when DropDownStyle = DropDownList in Windows 7

Let's say we have the following code in a Windows application: ComboBox comboBox = new ComboBox() { AutoCompleteMode = AutoCompleteMode.SuggestAppend, AutoCompleteSource = AutoCompleteSource.ListItems, DataSource = new string[] { "", "Ark", "Boat", "Bucket" }, DropDownStyle = ComboBoxStyle.DropDownList }; this.Controls.A...

Custom HttpHandler to block downloads of .wmv files

Hi I create a custom http handler to block download of .wmv files e.g. www.pakdev.net/videos/file.wmv (blocked by httpHandler). But the problem is that now silverlight cannot also stream these video files as they are blocked too. What should I do? ...

How do you randomly zero a bit in an integer?

Updated with newer answer and better test Let's say I have the number 382 which is 101111110. How could I randomly turn a bit which is not 0 to 0? The why; Since people ask me why, I simply need to do this, removing a bit from an integer. based on the answer here is the result(working one) I ran this using System; using System.C...

How to move a Shape on Canvas in WPF ?

Hi, I added a Rectangle to a Canvas like this: Canvas.SetTop(myRectangle, 150); Canvas.SetLeft(myRectangle, 80); canvas.Children.Add(myRectangle); Now I want to move the rectangle to other place, say (100, 100). What is the best way to do this ? Thanks ! ...

.NET Windows Service needs to use STAThread

I have created a Windows Service that will be calling out to some COM components, so I tagged [STAThread] to the Main function. However, when the timer fires, it reports MTA and the COM calls fail. How can I fix this? using System; using System.Diagnostics; using System.ServiceProcess; using System.Threading; using System.Timers; n...

How can I use SqlBulkCopy with binary data (byte[]) in a DataTable?

I'm trying to use SqlBulkCopy to import a bunch of data to our website. In most of the other areas we're using Entity model which uses byte arrays to represent binary data in SQL. However, SqlBulkCopy seems to be confusing byte[] with string. Everything seems to be working fine except for this one binary column which throws an exception:...

How to set DataGridView columns text format to uppercase by adding new property?

Hello, I have a custom DataGridView control and want to set the text format for custom columns in the designer (CellStyle builder). Let's say I want to make the text format to uppercase. After searching about this I've found some solutions with adding new events and then changing the text format but this is not what I want. I want to ...

Why my binding does not update on UIElement.RenderSize or UIElement.ActualWidth ?

I'm trying to data bind a TextBlock to the RenderSize of a Rectangle. Here is the code. <StackPanel x:Name="root"> <Rectangle x:Name="rect" Fill="Green" RenderTransformOrigin="0.5,0.5" Height="100" Width="100" /> <TextBlock Text="{Binding ElementName=rect, Path=Width}"></TextBlock> <TextBlock Text="{Binding Elem...

Is there an version of List that has Add and Remove events

I need a .net Collection that has Add and Remove events. Is there a premade version that has that? For example, I would update some internal counter when a user adds an item to the list via the event. (Not really what I plan to do.) ...

Hit Testing in WPF

Hi, I have an Ellipse on a Canvas and I'm doing a Hit Testing on it. Every time I click the stroke of the Ellipse, the test pass. If I click in the middle of the Ellipse, the test fails. This is good ! After I fill the ellipse like this: myEllipse.Fill = new SolidColorBrush(Colors.Blue); the test pass also when I click in the middle of t...

DotNET project resources and memory, what's going on?

Where can I find reliable information regarding project resources and memory? I'd like to know when resources are loaded into memory from the dll, when they are removed by the GC etc. Reason is my app carries the help-file topics as HTML-Strings inside the source, and I'm about to add the possibility to include images. I don't care if m...

How do I set an object to be the type of another object?

*strong text*I have a base class with a method in it for synchronizing data. However I need to be able to create a new object in the process that is the same as the parent object that inherited the base class. I want to do something like this: Sub Transfer(ByVal OBType As BaseClass) Dim A as new typeof(OBType) A.doSomething(...

Extension Methods on both IList and IEnumerable with the same name?

I have written some extension Methods to convert an IEnumerable and an IList into a string. Now, as IList inherits from IEnumerable, I have to name them differently. I just wonder if there is a way to avoid that? Can I have an extension Method on an IEnumerable and then a different one on an IList with the same name and the same signatu...

How to use the same info across multiple forms

I am working on my first C# program and have run into a brick wall. I want to be able to set and get variables throughout diferent forms in the same application. I created a class caleld "data" which contains the following: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Application1 { ...

Asynchronous Sockets - Handling false socket.AcceptAsync values

The Socket class has a method .AcceptAsync which either returns true or false. I'd thought the false return value was an error condition, but in the samples Microsoft provide for Async sockets they call the callback function synchronously after checking for failure, as shown here: public void StartAccept(SocketAsyncEventArgs acceptEven...

Find the number of divisors of a number given an array of prime factors using LINQ

Given an array of prime factors of a natural number, how can I find the total number of divisors using LINQ upon the original array? I've already figured out most of this problem, but I'm having trouble with my LINQ statement. Math Background: The prime factors of a number are the prime integers that divide evenly into the number wi...

How can I have multiple forms share a common menu in a Winforms app?

I have an existing .NET Winforms app made with a few complex forms, and 1) the forms all live for the life of the app, and 2) only one form is displayed at a time (the user switches between the forms) I need for these forms to share a common menu that will be processed by a single business-logic controller. (The visible form is als...

XPath 2.0 Libraries for .Net

Which XPath 2.0 libraries (apart from saxon) are available, preferably for .Net? ...