|
1. In Log4J you can use something called AsyncAppender. It takes references to already instantiated Appenders and uses them to write asynchronously.
2. Your are not wrong about writing to memory being faster than writing to disk.
But, if your ultimate goal is to have another layer of abstraction manage logging to disk for you faster than using System.IO you probably won't find anything that can. It won't be faster because that extra layer of abstraction will necessarily add some time to processing your logging plus writing the information to disk later.
Daniel
|
|
|
|
|
Hi there,
I'm facing the following problem: I'm writing test cases (using NUnit) for my classes and I have to test for example if properties will throw an Exception when there is an attempt to assign invalid values.
Say I have a Car class with a Speed Property I want it to throw an Exception if the user attempts to assign a value greater then 90.
My test code looks somewhat like this:
Car c = new Car();
bool bFailed = false;
try { c.Speed = 200; }
catch { bFailed = true; }
Assert.IsTrue(bFailed, "Property Speed accepts incorrect values");
When you have a ton of TestCases to write and a lot of Properties to test, this becomes quite cumbersome.
My question is, can this code be somewhat improved? Is there a more generic approach?
Thanks in advance.
Matthias
If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs.
(Lounge/David Wulff)
www.emvoid.de
|
|
|
|
|
try it like this...
Car c = new Car();
try {
c.Speed = 200;
Assert.Fail("Property Speed accepts incorrect values");
}
catch ArgumentException
{ }
Be sure to specify the type of the exception (not just Exception ).
my blog
|
|
|
|
|
Steven's answer is good, but this should be better:
[ExpectedException(typeof(IncorrectSpeed))]
public void TestSpeed()
{
Car c = new Car();
c.Speed = 200;
}
NUnit will allow you to tell the test exactly what exception should be thrown by the individual test as an attribute to the test method. The framework will pick up if the exception wasn't thrown and fail the test.
Of course if you want to make it more fine grained than that, say if you are expecting a SqlException with a specific error Number then Steven's code will allow you to pick up on that.*
* However, there is a newer version of NUnit that I've not used yet and it may have that feature already.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
|
I have a program that uses Acrobat Control for ActiveX. However, when a 'bad' pdf gets opened, Acrobat control throws an alert box saying the file is bad and cannot be opened. I want to be able to intercept this to 1) recognize that it happened, 2) prevent the user having to know and click the box, 3) automatically dismiss it.
Is this possible?
|
|
|
|
|
Have you tried monitoring the Windows messages for the control? If you listen for a particular message from the message pump, I'm sure you could intercept it and not pass it on to the Adobe control. Look at the Spy++ tool installed with Visual Studio and monitor the control for the message. Once you know what you're looking for, go back and setup a message hook to intercept it.
I'd bet Heath has a better solution (or might correct me that something posted above won't work) but hey it's a suggestion anyways.
Judah Himango
|
|
|
|
|
Thank You..
Could I send You my input file, so You can see if this code is OK??
|
|
|
|
|
I have two treeviews in a windows application.(leftside and right side)
and there are some nodes in these two treeviews.I want to drag a node from the left treeview to another node in the right treeview.
When the user drag- drop it,a line will be drawed between these two nodes.How can I do this?Could you help me pls?
|
|
|
|
|
One approach is that you handle the graphics drawing yourself.
Another approach is to use controls that specifically handle alot of this for you (such as Northwoods Go.NET controls).
This signature left intentionally blank
|
|
|
|
|
I am trying to read one text file, and create an Array.. Dos someone knews what am I doing wrong??
Can someone correct my code a little bit?
private void panel13_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
ArrayList nodes = new ArrayList();
FileStream file = new FileStream("C:\\NeckingRa\\Temp\\cut.dat", FileMode.Open,FileAccess.Read);
StreamReader sr = File.OpenText("C:\\NeckingRa\\Temp\\cut.dat");
String line;
while ((line=sr.ReadLine())!=null)
{
string s = sr.ReadToEnd();
string[] values = line.Split(' ');
}
sr.Close();
file.Close();
}
|
|
|
|
|
I would make the code look like this:
private void panel13_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
ArrayList nodes = new ArrayList();
StreamReader sr = File.OpenText("C:\\NeckingRa\\Temp\\cut.dat");
String line;
while ((line=sr.ReadLine())!=null)
{
string[] values = line.Split(' ');
nodes.AddRange(values);
}
sr.Close();
} The file variable is not needed and inside of the while look you were reading to the end of the file. Also you had never added the data in values to the nodes variable. I also like using @"c:\NeckingRa\Temp\cut.dat" in C# instead of the normal \\ that we all had to use in C++.
Steve Maier, MCSD MCAD
|
|
|
|
|
How to check if the thread is over? Then I can quit application.
|
|
|
|
|
You can wait for the thread to stop:
myThread.Join()
If you don't want to block the application, but display a warning, you can use Thread.Join to check the thread's state:
<br />
if( myThread.Join(1) ){<br />
}<br />
else{<br />
MessageBox.Show("There is still a running thread.");<br />
}<br />
|
|
|
|
|
i want to acquire an object`s Name property at run time.
(in example : this.Name)
thank.
|
|
|
|
|
TehMedic wrote:
i want to acquire an object`s Name property at run time.
(in example : this.Name)
You need to check into reflection, in particular the PropertyInfo[^] class. Given an Assembly you can iterate through all the Type 's by calling GetTypes() and for each Type call GetProperties() . One of the members of the PropertyInfo class is Name .
- Nick Parker My Blog | My Articles
|
|
|
|
|
thanks for your help.
I test your approach , for some control it work properly
but when use it for a component it return null.
?
|
|
|
|
|
I got a problem when using property grid:
I defined a class named ExampleClass with some properties.Then I did as follows:
ExampleClass myObject = new ExampleClass(...);
PropertyGrid myPropertyGrid = new PropertyGrid();
myPropertyGrid.PropertySort = PropertySort.Categorized;
myPropertyGrid.SelectedObject = myObject;
I would like the properties of myObject to be displayed in the property grid in the special order as I expected.Howerver,it didn't work.What should I do to achieve my purpose?
SOS,thank you!
|
|
|
|
|
|
Of course.
for each property of ExampleClass,Category attribute is attached.Problem does not lie here.I just want to properties of ExampleClass's object to be shown in property grid in some special order.Take properties A,B,C for example,A,B,C might be written in the code of class ExampleClass as follows:
public class ExampleClass{
...
public TypeB B { get {...} set {...} }
public TypeA A { get {...} set {...} }
public TypeC C { get {...} set {...} }
...
}
(ps:all required attributes have been already attached to A,B,C)
the special order I want to see is B first ,then A and C last in the property grid.of course,I set myPropertyGrid.PropertySort = PropertySort.Categorized.Now,you see,where the problem actually lies?
|
|
|
|
|
I have a C++ WinSock based client-server system which has the following design:
Client:
a. For each request, client connects to the server
b. Sends the input data
c. Waits for response (During this server does the processing and sends output)
d. Presents the results to the client
e. Socket connection is broken
Server:
a. Server waits in listen() loop
b. For each request, it spawns a thread
c. De-serializes input data
d. Does business logic and database operations
e. Transfers output to the client
Basically it is a synchronous multi-threaded socket based client-server solution with a simple design and adequate scalability. We have used it for years for upto 10 concurrent users and constant request-response cycles. Note that the request and response may consist of fairly large (e.g. 10 to 100 MB) files also.
Now we are re-designing the software with C#... I would like to know the optimal way to design the system, so that it is highly scalable. Please give your suggestions.
Thanks a lot !
|
|
|
|
|
The only suggestion I have is to use a ThreadPool on the server instead of spawning a thread directly. Threads tend to have high overhead for launching.
--
Joel Lucsy
|
|
|
|
|
I recommend going with either Web Services or .NET Remoting over HTTP hosted by IIS (which is exposed as a Web Service, so it's still one-way request/response). Scalability is handled by IIS leaving you with the higher-level functionality.
I also recommend implementing the WSE (http://msdn.microsoft.com/webservices/building/wse[^]) and using DIME to transfer files. It's a very simple API and does not require that the documents are serialized to a byte[] array like when you transfer it over the wire using Web Services or .NET Remoting. It's a binary wire format, and an industry standard to boot.
I recommend this because writing a socket client/server system and doing the serialization yourself is fine, but there's functionality for that already in the .NET BCL through Web Services and .NET Remoting.
Besides, Web Services are also an industry standard and open up new client possiblities that may otherwise be more difficult with a standard socket server (have to take endianess and packing into account).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Like Heath said, use a web service but we found that DIME
wasn't very good at handling large documents since it could
not stream. possibly u can use a webservice which returns
a http url of the file to be transfered. The client
receives the url and uses http protocol to download the
file. U can google for software which will help u to
download using http protocol
ex: sharpdownload project--sourceforge.net )
cool man
|
|
|
|
|
You can chunk large files using DIME - it's part of the specs.
Why does he need extra software to download files via HTTP? The .NET Framework BCL already has this. Use WebClient.DownloadFile for the simple way, or use HttpWebRequest and HttpWebResponse for a little more control and feedback. There's no need for an extra library. It's simply a waste.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|