|
okay i'm starting to get.. so all i have to do is to work in small steps... i really want to thank you for helping me ...so i'll start my program and if i have any question i will be thankfull if you could anwser me..
nagham
|
|
|
|
|
Yes, thats the idea - do it in small steps!
I'll answer if I can - and so will everyone else.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Hi,
I don't know whether I can help you construct the application, but I can provide you with a starting point. Here are a couple of link that can get you started.
C# and XML[^]
Adding CheckBox Controls to a Form from code[^]
I would say that the construction of your XML file is the secret. Do that correctly and the rest of the application will be a breeze!
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
if you are Using SQL Server 2005 Then
simple
Select * from QuestionTable Order by NewID() for XML AUTO
|
|
|
|
|
Hi!
I have a tricky question regarding exceptions in C#:
I need to know, somewhere in my code, if an execption has been thrown or not.
Basically, in the code below, when an unhandled exception is thrown within my using statement, the code will first call the Dispose() method on my UnitOfWork object (the one in the "using"), and THEN go in the catch statement. Wich is exactly what I want.
The only problem is, in my Dispose() method, I have no way to know if I'm there because of an exception (in that case I want to call some rollback code), or if I'm there because the code in the "using" ran ok.
My question is: how can I know if I'm in an error context from within my Dispose() method?
A few things you need to know:
- I'm working on a WinForm (so I can't use the ASP.NET Server.GetLastError())
- I can't use the event UnhandledException (as it can be handled externaly to my using statement, as showb below)
- I basicaly need the equivalent of Server.GetLastError(), but in WinForm...
<br />
try<br />
{<br />
<br />
using (Dao.GetUnitOfWork())<br />
{<br />
throw new Exception("Wanted Exception");<br />
}
}<br />
catch<br />
{<br />
}<br />
Thanks!!!
Antoine
|
|
|
|
|
You could pass the exception to UnitOfWork before Dispose is called. Something like this:
try
{
using ( var work = Dao.GetUnitOfWork() )
{
try
{
throw new Exception( "Wanted Exception" );
}
catch ( Exception x )
{
work.ExceptionWasThrown( x );
throw;
}
}
}
catch { ... }
If you don't need the exception object, but just whether any exception was thrown or not, then you could use a transaction pattern:
try
{
using ( var work = Dao.GetUnitOfWork() )
{
throw new Exception( "Wanted Exception" );
work.Commit();
}
}
catch { ... }
If Commit has not been called before Dispose, then you know an exception was thrown.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Hi Nick,
First, many thanks for your answer!
Unfortunately, it doesn't solve my problem:
Indeed, my try/catch was only there to show my point, but what I really want, is my UnitOfWork to dispose when I don't have a try/catch.
Of course, the best pattern would be to try:commit/catch:rollback everytime, but I wanted to simplify that by just using my "using" statement.
in other word, my question shouldn't have had any try/catch in the first place:
using ( Dao.GetUnitOfWork() )
{
Console.WriteLine("Everything works");
}
using ( Dao.GetUnitOfWork() )
{
Console.WriteLine("code always called");
throw new Exception( "Wanted Exception" );
Console.WriteLine("code never called");
}
public void Dispose()
{
if (???)
Commit();
else
Rollback();
}
So here, when Dispose() is called (knowing that my UnitOfWork object doesn't know the context in which it is used!), I need to know whether my code ran correctly or if I'm in an Exception situation...
Please advise if I'm confusing
|
|
|
|
|
There's no Exception.Current property or similar that I know of, so I think you're going to have to implement this explicitly.
My second example in my previous post can work. I've removed the name clash to make it clearer:
using ( var work = Dao.GetUnitOfWork() )
{
Console.WriteLine( "Everything works" );
work.RegisterSuccess();
}
using ( var work = Dao.GetUnitOfWork() )
{
throw new Exception();
work.RegisterSuccess();
}
partial class UnitOfWork
{
private bool _Success = false;
public void RegisterSuccess() { _Success = true; }
public void Dispose()
{
if ( _Success )
Commit();
else
Rollback();
}
}
When an exception is not thrown, work.RegisterSuccess() is called and _Success is set to true , so you can call Commit() in Dispose() .
When an exception is thrown, work.RegisterSuccess() is not called and _Success is still false , so you call Rollback() is Dispose() .
Is that what you wanted?
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Hi Nick,
Thanks for this, it's indeed a solution, though not perfect as the consumer of the code needs to remember to call the RegisterSuccess() method each time, which, IMHO, should be avoided.
But as you said, there's no Exception.Current or similar, so I'm afraid I won't be able to do it the way I wanted
Many thanks anyway for your input!
Cheers
Antoine
|
|
|
|
|
Hi Antoine,
No, not perfect! But I've used this pattern before and it is workable. If you forget to call RegisterSuccess, the code will fail in a big way, so it's quite an obvious bug.
Antoine Jaussoin wrote: Many thanks anyway for your input!
You're welcome.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
as Nick said.
work.RegisterSuccess() is what I suggest too.
I would probably call it work.Commit() though.
|
|
|
|
|
Hi all,
I want to enumerate all the distinct source of the events written in any event log in C#.
Can any one help me ?
|
|
|
|
|
Hi,
From all the event log sources or from a specific one?
Regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
What about something like this:
List<System.Diagnostics.EventLogEntry> entries = new List<System.Diagnostics.EventLogEntry>();
foreach (System.Diagnostics.EventLog eLog in System.Diagnostics.EventLog.GetEventLogs())
foreach (System.Diagnostics.EventLogEntry entry in eLog.Entries)
entries.Add(entry);
IEnumerable<System.Diagnostics.EventLogEntry> distinct = entries.Distinct();
entries = new List<System.Diagnostics.EventLogEntry>();
foreach (System.Diagnostics.EventLog eLog in System.Diagnostics.EventLog.GetEventLogs())
foreach (System.Diagnostics.EventLogEntry entry in eLog.Entries)
if (entry.Source == "TFSShellExt")
entries.Add(entry);
IEnumerable<System.Diagnostics.EventLogEntry> distinct2 = entries.Distinct();
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
|
Can we program Micro controller AVR with C# codings
Cause AVR is difficult for me to code it. and now i wanna to program micro
with C# ?
|
|
|
|
|
Probably not - the range of RAM available is 0.5K to 384K bytes, so I doubt it. The lower ones especially, are very unlikely. I know C is available for the AVR but you will be best to talk to the manufactures about your specific chip from the range to find out if C# is available, (or even possible)
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
|
Acording to MSDN:
The typical .NET Micro Framework device has a 32 bit processor with no external memory management unit (MMU) and could have as little as 64K of random-access memory (RAM).
The AVR is eight bit and some of the range is a lot less than 64K. Plus, I always take minimum specs as half the real-world minimum spec!
Have a look at the Porting Kit and see if you can use it...
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
the short answer is: no.
One could come up with a C# compiler that generates either C/C++ code or assembly code, so the language could be made available to any processor you choose (I haven't seen a single one though).
However, that is only a small fraction of the solution, as you probably want the whole .NET framework with its many namespaces and classes to be available too; and that would require lots of memory, and solutions for advanced topics such as reflection, which you may or may not need on your micro-controller.
|
|
|
|
|
Hello
how delete Maximize and Minimize button form to C#?
These function delete cloce button no how delete Maximize and Minimize?
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | 0x200;
return myCp;
}
}
|
|
|
|
|
You just need to set the Form's MinimiseButton and MaximiseButton properties to false.
|
|
|
|
|
|
Is there any particular reason for this? Properties will certainly be a great deal easier than manually overriding the control style.
|
|
|
|
|
try ..this
ControlBox=False
in the property window of the form.
Failure is Success If we learn from it!!
|
|
|
|