.net

Having a Backgroundworker refresh splash screen

Hi, Would it be theoretically possible to make BackgroundWorker in a class to periodically refresh existing splash screen form, or is that impossible? (I know that it's probably bad design, but currently I do not see any better way.) Please keep in mind that: I do not want the background worker to do the loading as it would be terrib...

Entity Framework 4 load Record by ID

So I am looking at creating a generic Interface to interact with my DataStorage of my objects one that I can swap out to use EF4 or SubSonic or NHibernate or some NoSQL option. So I have an ERD and every table has an auto incrementing int column "TableNameID" that is the primary key I am trying to figure out how to get a single record...

Preloading Winforms using a Stack and Hidden Form

I am currently working on a project where we have a couple very control heavy user controls that are being used inside a MDI Controller. This is a Line of Business app and it is very data driven. The problem that we were facing was the aforementioned controls would load very very slowly, we dipped our toes into the waters of multi-threa...

Is there a way to know in VB.NET if a handler has been registered for an event?

In C# I can test for this... public event EventHandler Trigger; protected void OnTrigger(EventArgs e) { if (Trigger != null) Trigger(this, e); } Is there a way to do this in VB.NET? Test for null I mean? MORE INFO I forgot to mention. I have classes written in C# but I am writing my unit tests in VB.NET. I am tryin...

String tokens in .NET

I am writing a app in .NET which will generate random text based on some input. So if I have text like "I love your {lovely|nice|great} dress" I want to choose randomly from lovely/nice/great and use that in text. Any suggestions in C# or VB.NET are welcome. ...

ResXResourceWriter Chops off end of file

I'm trying to create a .resx file from a dictionary of strings. Luckily the .Net framework has a ResXResourceWriter class. The only problem is that when I create the file using the code below, the last few lines of my generated resx file are missing. I checked my Dictionary and it contains all the string pairs that I expect. public v...

Simpler / more efficient method of nested if ... else flow?

I'm currently working on an emulation server for a flash-client based game, which has a "pets system", and I was wondering if there was a simpler way of going about checking the level of specified pets. Current code: public int Level { get { if (Expirience > 100) // Level 2 { if (Expirience > 200) //...

Why no ArgumentEmptyException in .NET ?

I am beginning to think I am doing something wrong. I mean they did place System.String.IsNullOrWhitespace finally but no ArgumentEmptyException class. public FilterItem(string name, IEnumerable<string> extensions) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullExce...

When should I implement globalization and localization in a .NET Application?

I am cleaning up some code in a C# app that I wrote and really trying to focus on best practices and coding style. As such, I am running my assembly through FXCop and trying to research each message it gives me to decide what should and shouldn't be changed. What I am currently focusing on are locale settings. For instance, the two error...

Update Entity through a new Object in LINQ to SQL

Hey Guys I'd like to update an entity via linq, but since I edit the entity in a view after serializing it, I don't have direct access to the entity inside the data context. I could do it like this: entity.property1 = obj.property1; entity.property2 = obj.property2; ... thats not cool... not cool at all. Next thing I tried is to do ...

How can i return dataset perfectly from sql?

i try to write a winform application: i dislike below codes: DataTable dt = new DataTable(); dt.Load(dr); ds = new DataSet(); ds.Tables.Add(dt); Above part of codes looks unsufficient.How can i best loading dataset? public class LoadDataset { public DataSet GetAllData(st...

SqlException: User does not have permission to perform this action.

I have been using my website (ASP.NET MVC) in visual studio but now I want to host it on my server. I published from visual studio onto the network share to be used. The server is running Windows Home Server, IIS 6 and SQL Server 2008 R2 (express). In Microsoft SQL Server Management Studio, I've attached the database and made sure that ...

Most efficient sorting of calculation on DataTable column calculation

Lets say you have a DataTable that has columns of "id", "cost", "qty": DataTable dt = new DataTable(); dt.Columns.Add("id", typeof(int)); dt.Columns.Add("cost", typeof(double)); dt.Columns.Add("qty", typeof(int)); And it's keyed on "id": dt.PrimaryKey = new DataColumn[1] { dt.Columns["id"] }; Now what we are interested in is the co...

DBConcurrencyException in winforms app due to munged time portion of datetime field

Hey All, I've got a winforms .net 2.0 application that's hitting a MS SQL 2008 server. I load up a DataSet from that server, expose a bunch of that dataset via bound winform controls & then push updates via SqlDataAdapters. One such adapter is attached to a table w/two key fields RecruitID and StatusDate. StatusDate is a DateTime fie...

How to sniff local outgoing network traffic in .NET without using PCap?

Hi there, I'd like to somehow hook into the local system's network stack to capture outgoing network packets without using Winpcap. Unfortunately it tends to crash my system every now and then. Is there a way to "sniff" outgoing traffic of the local system from a user space process written in a .NET language? Thanks a lot! Hendrik ...

Assert.AreEqual to not fail when comparing an enum and an int

I'm not sure if this is doable, but I will just give a shot. I am calling Assert.AreEqual() method. For the parameters, I'm passing... an enum value which has Int32 as the underlying type because I didn't specify the base type an int (Int32) value Assert fails because it sees that the enum is not int (which is definitely correct). H...

LinQ optimization

Here is a peace of code: void MyFunc(List<MyObj> objects) { MyFunc1(objects); foreach( MyObj obj in objects.Where(obj1=>obj1.Good)) { // Do Action With Good Object } } void MyFunc1(List<MyObj> objects) { int iGoodCount = objects.Where(obj1=>obj1.Good).Count(); BeHappy(iGoodCount); // do other stuff with 'objects' co...

ASP.NET MVC: Do I really have to create one view per action?

If I have a fairly crud-based area of my app, do I really have to create separate "Create" and "Edit" views? The HTML will be practically the same. I want an "Edit" and "Create" action to both render a "Show.aspx" view, but certainly Resharper 5 is complaining about there being no "Show" action. What's the best practice? ...

Best practice or performance difference between ToString() and & concatenation

When I am concatenating object values together to form a string in VB.NET, is there a difference in performance or a recommended best practice between using the & concat or the + concat with calls to .ToString() on each object? Example (which is faster or best practice): Dim result1 As String = 10 & "em" Dim result2 As String = 10.ToSt...

opening a file attachment from an outlook email using clickonce and a file association

Hi, I have a clickonce application (VS2010, .NET 4). I have registered a file association (.task), and this all works well. If I double click a file with the .task extension on the desktop the clickonce application opens and can open the file. If I email the file however, and double click the file from within outlook, I get the open/sa...