|
Yes, static methods and type constructors.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Well, yes, if you want to pick nits.
If you insist, instead of "does it make sense for any method to be called before a constructor?" it should be "does it make sense for any instance method to be called before a constructor?" or perhaps "does it make sense for any static method to be called before a type constructor?" or maybe the two combined.
Matt Gerrans
|
|
|
|
|
When instantiating ANY class, the constructor is always the first thing that is called.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Well, heck, if you were just going to blurt it out, couldn't you have done it in the form of a Vogon poem?
Matt Gerrans
|
|
|
|
|
Matt Gerrans wrote:
couldn't you have done it in the form of a Vogon poem?
I tried once, but I got these intestinal cramps and an inexplicable urge to gnaw off my right leg.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Actually, the static initializer (.cctor) is the first thing ever called, but only the first time for a type within a given AppDomain. But as far as instances go, yes you're right.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi,
I am adding items to a listview and want to make some items bold depending on a condition and some left as normal. The items.Bold property in the ListViewitems collection is a read only property and so i cannot set it. Is there a way to achieve this?
Thanks for the help.
Stephen
|
|
|
|
|
Set the items Font property
Ex:
item.Font = new Font("Microsoft Sans Serif",8,System.Drawing.FontStyle.Bold);
Sandeep Naik
|
|
|
|
|
Hello,
I have a C# program that reads data from an Excel sheet, and creates an Xml file from it. The Excel sheets are not modified, and the Excel app is hidden from the user.
Everything works fine exept when I quit my program before it finishes. When I do this, Excel stays open. The only way to tell this is to look in the task bar; the first time I did this I was surprised to see 8 Excel processes running!
There must be a way to tell Excel to quit when the process that started it quits... anybody know how I can do this? Thanks!
Jeremy O
PM Logic
http://www.jeremyo.com
|
|
|
|
|
If you using Excel automation com library from MS then it should be very simple. If your running Excel in any other way then I guess you can just kill the process.
|
|
|
|
|
The ApplicationClass defines a Quit method.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I have a question, that is probably really dumb to anyone who has any significant experience with C#, but I've searched for an answer and tried several different things (a few hours worth of trying different things!), so
I've elected to display my ignorance and ask for help from more experienced C# programmers:
To wit: I'm putting together two different services to run under XP/etc. To avoid any extra overhead and keep the resulting module small, I want to use just one executable w/o referencing any .dll(s) or other resources. To this end, though, I need to share one source file which will contain common code for both services. I have tried everything I can possibly think of to make C# (both .NET 2003 and C#Express 2005) use a single file in the construction of both 'projects'. If I do an 'add existing item', a copy gets moved in under the project. I can't do an 'add reference' to a .cs file. If I make it a 'miscellaneous' file, I can't get C# to find the namespace/class/etc.
There has to be a way to do this ... We used to do it routinely a hundred years ago when I started programming by the use of 'include' statements and the like ...
If someone could spare a few minutes, drop me an email and let me know how to do this.
Thanks,
toml@direcwayREMOVETHIS.com
|
|
|
|
|
You can't just reference a file. What you can do is create a shared assembly. Or just have a copy of your C# file like you mentioned.
If you don't want to have an assembly reference you can use "late binding". Then the C# term your looking for might be Reflections. Search MSDN if u have no experience with it.
|
|
|
|
|
Why not take care of this with a simple Visual Studio macro? Update to/from the file in the other project whenever it is changed.
Matt Gerrans
|
|
|
|
|
I guess many people coming from a C++ background try to do this thing. I wanted to do it myself, when I started with my first C# project.
After a few trials and errors and a little reading I found the following most logical way out:
(1) The code which you want to make common should either be a base class or a utility class.
(2) If not, make it so. Then you will have either BaseClass.cs or UtilityClass.cs file. Have a project for this class.
(3) Now I don’t know your case but typically, you have a single solution with multiple projects. Whichever projects require the BaseClass or UtilityClass functionality, do an ‘Add reference’ of the BaseClass or UtilityClass.
This works for me, do let me know your experience.
|
|
|
|
|
If you're using Sourcesafe, you can easily have files shared between multiple projects - that's probably the most straightforward way to do it (and means if you change the interface slightly in one project, it won't automatically break the other until you get the latest changes)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
How can I export data from database to an excel or word file in a non-web application with C#?
Tks
Thiago
|
|
|
|
|
You can use the COM libraries that MS provides. In your project go to add reference to the COM tab. If you have office installed you should be able to find a library similar to "Microsoft Excel 11.0 Object Library". This library allows you to automate Excel. The object model is very easy to learn. Notice that almost everything in the library is an interface. You can get started by going through the ApplicationClass class. Search MSDN for more information...
Same goes for Word
|
|
|
|
|
|
I know that .NET MUST to have a way to do this. But I don't know how.
1)On COM+, we can install a Component Server on a machine and our application on another. Then on the application Server we can access dll's running over Component Server and the our dll access de DB. There's a way to do it in C#?
2)I read some about MarshallByRef, some proxy dll samples (that doesn't work because it needs a physical path like d:\dlls\mydll.dll or a shared folder).
3)Can anybody help me? Please a step-by-step explaining how to do this....
thank you guys!!!
Wender Oliveira
.NET Programmer
|
|
|
|
|
You can still use COM+ using System.EnterpriseServices classes in .NET, and there's always Web Services and .NET Remoting, all of which are discussed in many articles here on CodeProject.
.NET Remoting is arguably the best route to go with .NET applications (use Web Services if you want to support legacy clients and clients on other platforms (like Java)). To get an overview of remoting, read the .NET Remoting Overview[^]. A couple of good books to read about .NET Remoting are "Microsoft .NET Remoting" from MS Press[^] and "Advanced .NET Remoting" by Ingo Rammer[^] (the former is probably better if you're new to .NET Remoting).
BTW - this isn't specific to C# but is available to all .NET implementations, and you don't need the path to an assembly (the proxy, in this case) so long as the assembly is resolvable (like in the GAC if it is strongly named, and all assemblies should be). Read How the Runtime Locates Assemblies[^] for more information on assembly resolution.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks Heath,
I'm reading this Remoting overview. But, let me try to explain a few better. I know that maybe you will say to ask it on ASP.NET forum. I have an web application and for security reasons I need to access my components (layers) on another machine... My Web application will talk to a dll on my component server and this dll will talk with my db and return the result to my web application. How to do this with an easy way? At suffering times, with vb, it would be possible by adding a dll on component service and making its msi instalation and adding a refference to that dll on web application. This is made with connection spool, ssl, authentication, etc... Do you know if exists some way to do this with C#.NET dlls?
Wender Oliveira
.NET Programmer
|
|
|
|
|
You implement shared interfaces in separate DLLs with very little implement. Implement those interfaces in your Remoting DLL then consume those interfaces in your client (proxy).
Again, for how the runtime locates assemblies, see the last link I gave you in my previous post. Either one of those books will help explain Remoting better, since it is a very complex subject and the .NET Framework SDK doesn't go indo enough detail to really explain it well.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
When windows performs the shutdown procedure is there a process involved?
If there is what is it called? can it be stoped?
|
|
|
|
|
When Windows is shutting down is sends the WM_QUERYENDSESSION message to all top-level Windows. Fortunately, the .NET BCL has encapsulated this for you in the SystemEvents.SessionEnding event you can read about at http://msdn.microsoft.com/library/en-us/cpref/html/frlrfMicrosoftWin32SystemEventsClassSessionEndingTopic.asp[^]. Set SessionEndingEventArgs.Cancel to true to stop the shutdown.
If you'd like more information, click "Search comments" above and search for WM_QUERYENDESSION since I've covered this in more detail many times in the past.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|