|
|
Write a logger class that has a single static method:
public class Logger {
static public Log(string msg);
}
Then you would call the Log method like this:
Logger.Log("Sent a message");
Of course the logger class would have a bunch of private methods and classes underneath to use a logging instance of some type that does the work.
An alternative is to write a classic Singleton.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Inherit a class from System.Diagnostics.TraceListener. On application start, add an instance of this class to the System.Diagnostics.Trace.Listeners and/or System.Diagnostics.Debug.Listeners collections.
Every time you use Trace.Writexxx or Debug.Writexxx, it will be logged through your class. If you change/expand your logging facilities at some time, you don't have to change any client code, just your TraceListener.
|
|
|
|
|
I am launching a cmd prompt via my C# app that runs "net stop mssqlserver /y". This works in Debug mode, but the compiled application opens the cmd window and then closes it immediately without executing the line. Anyone else experienced this?
Attatching debug app exe when solution in debug mode also fails to complete the operation
|
|
|
|
|
|
Also I'm assuming you're using System.Diagnostics.Process.Start instead of ShellExecute, right?
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
This is my code:
-----------------------------------------
Process commandPrompt = new Process();
commandPrompt.StartInfo.FileName = "C:\\Windows\\System32\\cmd.exe";
//commandPrompt.StartInfo.Arguments = command;
commandPrompt.StartInfo.UseShellExecute = false;
commandPrompt.StartInfo.RedirectStandardInput = true;
commandPrompt.Start();
commandPrompt.StandardInput.WriteLine(command);
-----------------------------------------
I am trying your suggestions - thanks
|
|
|
|
|
Hello,
Is it possible to easily swap values of primary key column between two rows of one DataTable object? I've been trying it like this;
<br />
DataRow dr1=dt.Rows.Find(5);
DataRow dr2=dt.Rows.Find(10);<br />
dr1.BeginEdit();<br />
dr2.BeginEdit();<br />
dr1["item_Id"]=10;<br />
dr2["item_Id"]=5;<br />
dr1.EndEdit();
dr2.EndEdit();<br />
Same thing happens with dt.AcceptChanges();
Is there a way how to achieve this? Any clues are highly appreciated!
Rado
|
|
|
|
|
DataRow dr1=dt.Rows.Find(5);
DataRow dr2=dt.Rows.Find(10);
dr1.BeginEdit();
dr1["item_Id"]=-1;
dr1.EndEdit();
dr2.BeginEdit();
dr2["item_Id"]=5;
dr2.EndEdit();
dr1.BeginEdit();
dr1["item_Id"]=10;
dr2.EndEdit();
dt.AcceptChanges();
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Oh thanks a lot! How come this didn't come to my mind
Rado
|
|
|
|
|
Because it's common sometimes to overlook the easy stuff in search of the more complex solution. We all do it
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
(Repeated from our private email so that others searching for this answer will find it.)
Hi Rado,
Ever have one of those problem that just eats at you? Well your situation has bugged me for some time because I just knew there had to be an easier, more elegant way. There is......
The problem was that BeginEdit calls for the two DataRow objects were disabling the constraints for the respective rows, but once you called EndEdit for one DataRow , the primary key value for that first row conflicted with the (not yet committed) second DataRow object. Therefore, I had to assume that there was a higher level way of turning off constraints - either the DataRowCollection or the DataTable . Finally, I found the DataTable::BeginLoadData and DataTable::EndLoadData method, which turn off and on, respectively, constraint checking and index maintenance for the entire table.
<br />
table.BeginLoadData();<br />
<font color=green>
table.EndLoadData();<br />
Note: You mentioned the fact that someone suggested turning constraints off for the entire DataSet . As this technicall will work, using BeginLoadData and EndLoadData will affect only one table instead of all the tables for a given DataSet .
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Before editing your DataRow s, set DataSet.EnforceConstraints to false .
try
{
dt.DataSet.EnforceConstraints = false;
}
finally
{
dt.DataSet.EnforceConstraints = true;
}
|
|
|
|
|
|
Hi
We would like to be able to use the different hardware fonts that exists on most printers, when we use the windows driver "Generic / Text Only" *.
We have written some code that enables us to write text to a "Generic / Text Only" (GTO) printer, but despite many attempts we haven't been able to change the font.
For writing text we use the importer legacy function WritePrinter().
Any ideas?
*) We have to use this driver since we also want to use our code for POS printers etc.
Mads
|
|
|
|
|
use the printing events. I cant remember the name but an event rises before it starts a print. you can then query for the selected fonts like a font-family in html
|
|
|
|
|
Since .NET print any stuff as graphics, the standard .NET printing mechanism doesn't work with a "generic / text only" printer.
Having tried it anyway, we found out that it didn't raise the event (and the code was ok - the event was raised if we choose any other printer).
Personally, I think we have to use some escape sequences - but I haven't been able to find out how to write them.
Thanks for your reply.
Mads
|
|
|
|
|
Perhaps you'll have to use the Windows printer API.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Have you tried crystal reports. I had the same issue with off brand printers. Crystal prints as graphics yes but it can be switched to character printing
|
|
|
|
|
Is there any Method/utlity/Class which can help me in process Monitoring? Startup/Exit/busy etc status..
VikramS
|
|
|
|
|
Take a look at the System::Diagnostics.Process class:
Exit Notification -> Process.EnableRaisingEvents
Enumerating running processes -> Process.GetProcesses
Finding processes - > Process.GetProcessByName
Alive? -> Process.Responding
That should get you started in the right direction.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Hi! I try to create a target bitmap alike the source bitmap ( in size, in pallete). I hope the target bitmap will be created black(or 0) on every pixel. And then program generate the content of target according to the source one, if some pixel isn't be filled it will be still black.
first trial:
dst = (Bitmap)src.Clone();
BitmapData bmSrcData = src.LockBits(new Rectangle(0, 0, src.Width, src.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
BitmapData bmDstData = dst.LockBits(new Rectangle(0, 0, dst.Width, dst.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
//do some processing on BitmapData
This one work! but it seems clone waste much on copying the content. i wanna it be black, so i have to fill it 0 myself. copy and fill are useless duplicate work.
Second trial:
dst = new Bitmap(src.Width, src.Height, src.PixelFormat);
BitmapData bmSrcData = src.LockBits(new Rectangle(0, 0, src.Width, src.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
BitmapData bmDstData = dst.LockBits(new Rectangle(0, 0, dst.Width, dst.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
dst will not has the same palette as src. After the process, dst will be a color image even src is a formerly gray one.
Third one:
dst = new Bitmap(src);
BitmapData bmSrcData = src.LockBits(new Rectangle(0, 0, src.Width, src.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
BitmapData bmDstData = dst.LockBits(new Rectangle(0, 0, dst.Width, dst.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
can't execute! the second LockBits will raise error. anybody know why?
I really puzzled by these methods! any guru can explain what's on earth are these create functions doing? and what's the best way to get my aim?
|
|
|
|
|
novachen wrote:
can't execute! the second LockBits will raise error. anybody know why?
It appears that dst and src might be the same instance, and thus cannot be locked twice. My guess
Unfortunately I cant help you with the others...
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
How to add my componet in to VS.NET (like that Visual Assist)??
Someone can help me, please!!!
Thanks
|
|
|
|
|
hi,
i want to know how to make a function including a parameter with default value?
somethings like this...
public void functionA(int A, int B = NULL)
{
// ...
}
any help?
thanks,
jim
|
|
|
|