Archive for April, 2011
Not enough storage is available to complete this operation
0http://msdn.microsoft.com/en-us/library/ms681382%28VS.85%29.aspx
- ERROR_OUTOFMEMORY 14 (0xE) – Not enough storage is available to complete this operation.
- http://stackoverflow.com/questions/2881419/not-enough-storage-is-available-to-complete-this-operation-program-or-storage-m
- http://social.msdn.microsoft.com/Forums/en/sqlce/thread/06f90b9c-9c19-499e-b016-c161949251bc
- http://msdn.microsoft.com/en-us/library/aa454885.aspx#effective_memory_storage_power_mgmt_wm5_topic2
- http://support.microsoft.com/kb/326164
Consider using System.IO.Path.Combine() instead of string concatenation
0http://dotnettipoftheday.org/tips/SystemIOPathCombine.aspx
Let’s review the following code for creating a file path:
public string GetFullPath(string fileName)
{
string folder = ConfigurationManager.AppSettings["MyFolder"];
return folder + fileName;
}
This code is prone to error. For example, when you set the folder setting, you have to remember to make sure it ends with a slash. To avoid such problems use Path.Combine() method which will ensure that the folder has ending slash:
public string GetFullPath(string filename)
{
string folder = ConfigurationManager.AppSettings["MyFolder"];
return Path.Combine(folder, filename);
}
Use Path.GetRandomFileName() or Path.GetTempFileName() when working with temp files
0http://dotnettipoftheday.org/tips/PathGetRandomFileName.aspx
Do not reinvent function for generating unique name for temporary files. Use one of the existing methods:
- System.IO.Path.GetTempFileName() – use this method if you want to create temporary file in user’s temp folder.
- System.IO.Path.GetRandomFileName() – use this method if you just want to generate unique file name.
?? operator (C#)
0http://dotnettipoftheday.org/tips/double_question_mark_operator_cs.aspx
The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand. For example:
int? x = null; ... // y = x, unless x is null, in which case y = -1. int y = x ?? -1;
The ?? operator also works with reference types:
//message = param, unless param is null //in which case message = "No message" string message = param ?? "No message";
Speed testing in .NET – System.Diagnostics.Stopwatch
0http://dotnettipoftheday.org/tips/system_diagnostics_stopwatch.aspx
System.Diagnostics.Stopwatch is a replacement for what most people probably do to identify the time spent on excecuting a method. The process usually goes something like: create a DateTime.Now value at the start and then subtract the ending DateTime.Now to get the TimeDuration value that elapsed.
As an alternative, the Stopwatch class was built using low-level API calls, with less overhead than other .NET methods. If the hardware and Windows version of the computer support a high-resolution performance counter, it will use this counter instead of the standard PC clock.
Here is a simple example:
More >
COALESCE function instead of long CASE WHEN … ELSE (T-SQL)
0Instead of using long “SELECT … CASE WHEN … ELSE …” construction, you can use the COALESCE function when you need to find a value that is not NULL. Lets review the following T-SQL expression, in which we need to select an available “source”:
http://dotnettipoftheday.org/tips/sql-coalesce.aspx
SELECT TheSource =
CASE
WHEN localSource IS NOT NULL THEN localSource
WHEN intranetSource IS NOT NULL THEN intranetSource
WHEN internetSource IS NOT NULL THEN internetSource
ELSE ''
END
FROM ...
Now lets rewrite the code above using COALESCE function:
SELECT
Correct event invocation
0http://dotnettipoftheday.org/tips/correct-event-invocation.aspx
Be aware that if there are no subscribers a .NET event will be null. Therefore when raising the event from C# test it for null first.
public event EventHandler SelectedNodeChanged;
protected virtual void OnSelectedNodeChanged(object sender, EventArgs e)
{
//Event will be null if there are no subscribers
if (SelectedNodeChanged != null)
{
SelectedNodeChanged(this, e);
}
}
However in multithreaded application the last subscriber can unsubscribe immediately after the null check and before the event is raised. To avoid a null reference exception make a temporary copy of the event.
Keyboard shortcuts for Word
0Command Name Shortcut Keys ------------------------------------------------------------------------ All Caps CTRL+SHIFT+A Annotation ALT+CTRL+M App Maximize ALT+F10 App Restore ALT+F5 Apply Heading1 ALT+CTRL+1 Apply Heading2 ALT+CTRL+2 Apply Heading3 ALT+CTRL+3 Apply List Bullet CTRL+SHIFT+L Auto Format ALT+CTRL+K Auto Text F3 or ALT+CTRL+V Bold CTRL+B or CTRL+SHIFT+B Bookmark CTRL+SHIFT+F5 Browse Next CTRL+PAGE DOWN Browse Previous CTRL+PAGE UP Browse Sel ALT+CTRL+HOME Cancel ESC Center Para CTRL+E Change Case SHIFT+F3 Char Left LEFT Char Left Extend SHIFT+LEFT Char Right RIGHT Char Right Extend SHIFT+RIGHT Clear DELETE Close or Exit ALT+F4 Close Pane ALT+SHIFT+C Column Break CTRL+SHIFT+ENTER Column Select CTRL+SHIFT+F8 Copy CTRL+C or CTRL+INSERT Copy Format CTRL+SHIFT+C Copy