|
With unmanaged code you get:
:: Optimized compiling. The final code is optimized for the exact processor it will be run on.
:: System independance. You can run your progam in any system that supports the framework. Currently there is an implementation in Linux. I would expect more to come.
:: Security. The program can be sandboxed, totaly isolating it from any resources it doesn't need.
Regarding security, just make sure that the program never destroys the data it's using, and always cleans up any unmanaged resources. After that it's more a question of quality. A good program doesn't crash just because you entered some text in a field that should be numeric.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks Guffa.
Which are the operating systems that support the .net framework? Like if I creat a .exe in C# will it run on win98 and older version. Do those operating systems support the framework? And, can we develop applications for Linux Using C#?
Amit
|
|
|
|
|
"Supported Operating Systems: Windows 2000; Windows 98; Windows ME; Windows NT; Windows XP"
Microsoft .NET Framework 1.1[^]
Mono is available for Linux/x86, Linux/x86_64, Linux/S390, Windows 2000+ and Mac OS X.
Mono[^]
---
b { font-weight: normal; }
|
|
|
|
|
can anyone help to point the issue? I have struggled this for a day and cannot get any where.
I want to create a COM+ object remotely. The code is really simple as below.
I also did "gacutil -i "and "regsvcs" for both interface dll and COM+ object. also double check the existance in GAC and regedit.
When executing the test client at the line, NewPDFNoQueNew myPDF = new NewPDFNoQueNew();,i did see a DLLHOST.exe kicked off, then at this time, i am able to attach DLLHOST.exe from the Visual Studio COM+.
But some how, it throws "unable to cast object of type PDFNoQueNew.PDFConvNoQueNew to NewPDFNoQueNew".
Thank you so much in advance.
1 Interface DLL.
using System;
using System.Diagnostics;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
using System.Reflection;
namespace IPDFPrintTestNew
{
[Guid("050355EC-83C9-4723-9E2D-AAAAD3CA3BAF")]
public interface IPDFPrint
{
string PDFPrintMethod();
}
}
2. COM+ object //add a reference to IPDFPrintTestNew
using System;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
[assembly: ApplicationName("PDFNoQueNewApp")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(Value = false,
Authentication = AuthenticationOption.None)]
namespace PDFNoQueNew
{
[Guid("050355EC-83C9-4723-9E2D-AAAAD3CA3FFF")]
public class PDFConvNoQueNew: ServicedComponent, IPDFPrintTestNew.IPDFPrint
{
public string PDFPrintMethod()
{
return ("ok");
}
}
}
3. Client test //add a reference to IPDFPrintTestNew
using System;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
namespace PDFNoQueNewClientTest
{
class Class1
{
[ComImport, Guid("050355EC-83C9-4723-9E2D-AAAAD3CA3FFF")]
class NewPDFNoQueNew
{
}
[STAThread]
static void Main(string[] args)
{
NewPDFNoQueNew myPDF = new NewPDFNoQueNew();
IPDFPrintTestNew.IPDFPrint iPDF = (IPDFPrintTestNew.IPDFPrint)myPDF;
string result = iPDF.PDFPrintMethod();
return;
}
}
}
|
|
|
|
|
hi
just a simply performance question.
when my_object is null what is the best code between ?
<br />
try<br />
{<br />
my_object.myfunct();<br />
}<br />
catch(Exception)<br />
{...}<br />
and
<br />
try<br />
{<br />
if(my_object==null)<br />
throw(new Exception("Object is null"))<br />
my_object.myfunct();<br />
}<br />
catch(Exception)<br />
{...}<br />
|
|
|
|
|
This is a good little article that will enlighten you on the subject: Performance Implications of Exceptions in .NET[^]
By the way, you should probably try to catch a specific exception (NullReferenceException ) instead of the catch-all Exception .
Matt Gerrans
|
|
|
|
|
Avoid the exception alltogether. If you check for the null value, you don't need to throw an exception, as you have control over the situation. Exceptions should only be used to handle situations that you can't control in any other way.
---
b { font-weight: normal; }
|
|
|
|
|
Say I want to draw the following numbers at equal intervals inside of
a Rectangle drawn on a WinForm (call it graphRect).
For instance:
1.0 2.0 3.0
I've been using:
float myfloat = 1.0f;
string myString = myfloat.ToString();
for( int x <= graphRect.Width....
{
DrawString(myFloatString.ToString("f1"), graphRect.X + ....
}
Is there a better way?
How best to increment the float through each iteration?
thanks
|
|
|
|
|
hi, is it possible to use a XML Dokument as a Database? because i dont want to install a SQL Server!
how can i establish a Odbc or Oledb Connection to the XML Database? than i want to fill the DataSet and display it in a DataGrid!
thx in advance! bye
|
|
|
|
|
You can create your schema definition using Visual Studio's schema editor. It is very similar to "Enterprise Manager". Just keep in mind the following: "Create Element" to create a table. Add "Attributes" instead of elements to specify the columns (it makes it much more readable). You can apply same rules as Enterprise Manager such as Cascaded Foreign Keys, auto-increments, etc. In your code use DataSet to load your schema. Your Dataset has access to all tables and your tables have access to all rows and columns. Each DataTable can have more than one DataView that filters the data from same table based on different criteria. Use DataTable.Select to select specific rows based on criteria....etc, etc. Hope this is of some help.
|
|
|
|
|
If I have the following in my class
private static object padlock = new object();
Then somewhere in my class I happen to call this more than once
lock( padlock )
{
}
If I call lock on padlock more than once what is happening behind the scenes?
1) Are the number of references to padlock incremented?
2) Or is the Exit method just called once for each lock()
Thanks
|
|
|
|
|
Lock uses System.Threading.Monitor.Enter() and System.Threading.Monitor.Exit() to lock and unlock the object.
MSDN:
"It is legal for the same thread to invoke Enter more than once without it blocking; however, an equal number of Exit calls must be invoked before other threads waiting on the object will unblock."
---
b { font-weight: normal; }
|
|
|
|
|
Yeah, I found that description but my boss wouldn't except it as a definative answer.
He wants to know how the compiler/framework knows that you haven't called
Threading.Monitor.Exit() enough times to match your calls to Threading.Monitor.Start().
Since I couldn't prove it he made me change my code.
thanks for your response.
|
|
|
|
|
smesser wrote:
Yeah, I found that description but my boss wouldn't except it as a definative answer.
If the word straight from the horses mouth won't do it, what will?
smesser wrote:
He wants to know how the compiler/framework knows that you haven't called
Threading.Monitor.Exit() enough times to match your calls to Threading.Monitor.Start().
Why? Does it matter how it works? Isn't it enough to know that it works?
---
b { font-weight: normal; }
|
|
|
|
|
He is concerned that it might not be thread safe.
I know it seems picky. But this situation exists in a File logger and several threads have access to the log. He is worried that with multiple locks the logger will get into a dead-lock situation.
The MSDN info that you quoted is good enough for me. However, if I could have shown him in the documentation that each time you called ...Monitor.Start() on an object there was a mechanism for counting the references to the object being locked and likewise during calls to ...Monitor.End() if the docs stated that the number of references to the locked object was decremented he would have excepted that.
But the documention only states that you should ensure that you call End() for each time you call Start() which to him means that you can't be sure in a threaded environment that you won't have a dead-lock situation.
Thanks
|
|
|
|
|
Of course it's thread safe. This is one of the mechanisms used to make things thread safe.
The documentation says that the waiting process does not get access to the code until you have ended the same number of locks that you started. That means that the system keeps track of the number of locks, otherwise the waiting process would get access to the code when you ended the innermost lock.
I tried to investigated the Enter and Exit methods of Threading.Monitor using .NET Reflector, but that did not reveal anything about the implementation. They are implemented internally in the CLR.
If you replaced the lock with something else, what is that then? Is that thread safe?
---
b { font-weight: normal; }
|
|
|
|
|
I can use a single lock I just had to reengineer my code to get rid of the nested lock.
Don't misunderstand I agree with you completetly.
On Monday I will throw your statement at him and see if it will satify him.
Guffa wrote:
The documentation says that the waiting process does not get access to the code until you have ended the same number of locks that you started. That means that the system keeps track of the number of locks, otherwise the waiting process would get access to the code when you ended the innermost lock.
|
|
|
|
|
Greetings All,
I posted this message in VC forum, but didnt get feedback, may i could get feedback here.
I do boolean operations on regions acquired from paths, after the boolean operations i would like to set resulting region to a path.... I do not know if this is possible and leaning towards that it is not. has anyone tried this before?
Thanks in advance
Sincerely,
Max Pastchenko
|
|
|
|
|
I found out that it is not pissible.
I guess a solution would be simple storing that region and diplaying it long with paths on a bitmap.
Sincerely,
Max Pastchenko
|
|
|
|
|
I have a for loop that labels tick marks on a graph axis. I can't make it do what I want.
I want this:
| | | C | | |
-3.0 -2.0 -1.0 +1.0 +2.0 +3.0 etc..
I keep getting this:
| | | C | | |
-3.0 -2.0 -1.0 +0.0 +1.0 +2.0
My loop uses a DrawLine(x1, y1,...) to draw the ticks
It also uses a DrawString(f.ToString("f1"), ....) to draw the numbers
I then increment the float for the next iteration.
I've tried a few control structures "if else..." but keep ketting similar results...
Any ideas? Thanks in advance
|
|
|
|
|
Message didn't format the way it was written. Each tick should line up over each float with "C" as the (0,0) coordinate. I want it NOT to label the "0.0" at the origin but then label the +1.0 .
|
|
|
|
|
Use an integer for the loop counter instead of a float. A float value seldom is an exact value, so if you compare it to 0.0 it might not say that they are the same, as the value in your variable might actually be something like 0.0000000000000001.
---
b { font-weight: normal; }
|
|
|
|
|
I have a situation where I have three separate C# class objects that all have the same properties and methods so their signatures are the same in all respects except for the class name (I am writing a code generator for personal use with each class representing a different design pattern).
There is also a core class which operates as a control point to call each class depending on which design pattern is chosen. The challenge I have is that it would be extremely cumbersome and complex in the control class to populate the many properties and call the many methods separately for each design pattern class so I was attempting to declare a generic object type first, instantiate the proper pattern class inside a switch block, assign the instantiated pattern class to the generic object type outside of the switch block, and finally populate all the necessary properties and call all the necessary methods using the generic object type class.
The result in many different attempts to do this always ends up with the compiler returning an error message saying the generic object type class does not contain the properties or methods specifed and I am looking for a way to make this happen.
Psuedo-code for what I am trying to do:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Declare generic object type
object cNetPattern;
// Determine design pattern requested
switch(m_iNETDesignPattern)
{
case (int)eNETDesignPattern.TDSTraversal:
// Instantiate TDS Traversal design pattern class 'clsPattern_1' here
break;
case (int)eNETDesignPattern.Collection:
// Instantiate Collections design pattern class 'clsPattern_2' here
break;
case (int)eNETDesignPattern.ClassProvider:
// Instantiate Class Provider design pattern class 'clsPattern_3' here
break;
}
// Assign specific class type object to generic object type
cNetPattern = clsPattern_n; // Where 'n' is the specific pattern class object instantiated above
// Populate properties and call methods
cNetPattern.bProperty1 = m_bProperty1;
cNetPattern.Method1();
...many, many more properties and methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NOTE: As mentioned all three specific design patterns have the same property and method signatures.
Any help would be grealy appreciated!
Dennis M.
|
|
|
|
|
Dennis,
Your explanation was a little confising, but is this what you're trying to do?
object X;
switch(thang)
{
case a:
X = new X1();
break;
case b:
X = new X2();
break;
case c:
X = new X3();
break;
}
X.Property1 = 13;
X.Method42();
...
If so, put all the properties and methods in X and then have X1, X2 and X3 inherit from X. I assume you'll also have to overload X's methods in X1, X2 and X3. Just because two classes share the same signatures doesn't mean they can be interchanged. It's the interface that matters.
Good luck,
Andrew
|
|
|
|
|
Yes your example is exactly what I am trying to do. So that means that I would have a base class of X with all properties and methods specified, and in my case I would have all the methods in the base class empty and overrideable so that the derived classes (X1, X2, X3) could provide thier own logic by overriding the base class method. This sounds like it will work for me which I will try asap - Thanks for the reply!
Dennis
|
|
|
|