|
As Dave said, that really isn't possible.
There is one way, though it's a pretty big hack and won't really solve your problem. You can create a launcher with it's own config file that specifies the path of the executable (optional) and the path to the .config file. This launcher is executable as normal but then grabs the path to your current Windows Service executable (or hard-code it, though I recommend against that), sets up a second AppDomain (see AppDomain.CreateDomain ) and sets the AppDomain.SetupInformation.ConfigurationFile using the path you configured.
This isn't recommended, though. Those .config files are separate for security reasons and because a true application boundary exists (they're obviously both separate executables). Also, A Windows Service and an ASP.NET web application really share very little of the .config in common, such as the appSettings and assemblyBinding (as well as other runtime sections).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hmmmm... That solution is... ummmm... interesting.
Heath Stewart wrote:
A Windows Service and an ASP.NET web application really share very little of the .config in common
I realise that the Web.cofig file contains many settings that the Service won't need and vice versa, but there is a lot of commonality. The database connection strings, the directory paths for the data files, timeout settings and so on. In total there are about 40 settings that are shared between the web application, the service and some unix processes. Things like the database connection strings are actually split up into parts because of the different technologies.
|
|
|
|
|
Interesting or not, it's fact. The worker process for ASP.NET sets up the AppDomain to use Web.config. The loader information in the PE/COFF executable bootstraps mscoree.dll, which uses the executable filename + .config.
You might consider writing a custom configuration section (see IConfigurationSectionHandler ) using something as simple as XML Serialization to get an object. You could also reference a common filename in your config section where your handler gets that file and then deserializes that (since a .config file is nothing more than XML) or parse the DOM yourself.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Interesting or not, it's fact.
I realise that. I meant that it was "interesting" in a "I really don't want to be implementing major hacks" kind of way.
What about the <appsettings file="some_other.config">? I'm stumpt at why that doesn't work either. Any ideas?
If not it looks like I'm either going to have to code around it, or duplicate the settings.
Cheers,
Andy
|
|
|
|
|
I already answered your question, unless you're talking about a different one. ASP.NET and Windows Forms applications (or even console applications - anything that is self-executable) use a different way to refer to their .config files. As I mentioned, though, just make your own IConfigurationSectionHandler implementation and implement it in such a way that it can pull "global" settings from a file or some other backing store.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a listbox that is periodically recieving lines of text. The listbox eventually gets more info than is needed. I would like to have it so that for each new line of text that is added to the top of the listbox, the oldest line is removed from the bottom (once the form is "full"), so that there can be a finite number of lines of information, with the new constantly replacing the old. I haven't been able to find out or figure out how to do that.
Thanks very much indeed!
|
|
|
|
|
You should be able to use
ListBox1.Items.Insert(0, "MyNewItemGoesHere")
Try
ListBox1.Items.RemoveAt(25)
Catch
End Try
The Try catch block is in there because I don't know what would happen if you tried to RemoveAt an index that didn't exist yet.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
What's all this VB.NET code you're writing in the C# forum lately, Dave? Have you converted to the "dark side"?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I float back and forth, dark-side...light-side...
You really have to taste them both before you commit to one power or the other...
I was actually only trying on the black suit and cape with the funny respirator noise. I can't get the James Earl Jones voice to work though! Oh well...back to C# I go!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
I can't get the James Earl Jones voice to work though!
You won't sound like him with your helmet off.
C# vs. VB.NET: really, I don't care. Good developers (that includes you, of course) can switch back and forth realizing that it's only a difference in syntax (although knowing a little of that syntax is necessary, which I do I hate to admit). It's good to brush up on VB.NET syntax from time to time, but remember that even Luke stopped from killing his father before it was too late and he was completely turned!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Oh! I found the problem! I forgot to change the batteries in my helmet!
I'm jumping back and forth between both forums... I just forget which one I'm in at the time. The same thing happens while I'm doing stuff in VS. I can be writing code in VB and suddenly start typing C# stuff or the other way around. Little red squiggly lines start poppin' up all over the place...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
OK. CHANGE THE CHANNEL!
--End of line
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Damn! VB code in the C# forum again!
OK...translated:
ListBox1.Items.Insert(0, "MyNewItemGoesHere")
try
{
ListBox1.Items.RemoveAt(25)
}
catch
{
}
What forum am I in again?? Damn! 35 years old and I can't remember which way is up!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I like to extend the TreeNode class through Inderitance to add a string property to the class. The TreeNode Class has 5 constructors, do I need to provide 5 contructors in my TreeNode class ? Is there some way I can pass a variable set of paramters to the base class's constructor ?
|
|
|
|
|
Guinness4Strength wrote:
do I need to provide 5 contructors in my TreeNode class
No, and you'll still be able to call those 5 constructors on your inherited class.
Guinness4Strength wrote:
Is there some way I can pass a variable set of paramters to the base class's constructor ?
Why? You can provide your own constructors that call the base constructors, and optionally, set various properties of the TreeNode while in the body of your constructor.
#include "witty_sig.h"
|
|
|
|
|
You only need to define the constructors that you want, but be sure to call the base class's corresponding constructor like so:
public class MyTreeNode : TreeNode
{
public MyTreeNode(string text) : base(text)
{
}
} Also be sure that you cast the TreeNode from the tree to your class (ex: MyTreeNode ) when you need to access that string. The TreeNodeCollection will store a reference to your derivative class, but will only return a TreeNode since that's all it deals with. That object is still an instance of your derivative class, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok, thanks Heath.
I assumed I still needed to define the constructors in my class, but wasn't sure...
|
|
|
|
|
No, you don't have to provide 5 constructors for your TreeNode class. Since your extending the existing TreeNode class, all you have to do is supply your own constructor if one of the existing ones is not suitable. You could override the existing contructors to provide slightly different functionality, like filling in your extended fields with default data, or provide a completely new one so long as the signature of your constructor doesn't match an existing one.
If you wanted to provide a constructor that took two String parameters and an existing TreeNode object, instead of a single String and TreeNode, you could because there is no matching constructor in the base class constructor list.
public TreeNode( string text, string altData, TreeNode[] children );
Now, if you wanted to provide a new constructor that takes the same type and same number of parameters, like:
public TreeNode( string text, TreeNode[] children );
and
public TreeNode( string altData, TreeNode[] children );
Then you would have to rearrange your parameter list because you can't ahve two constructors with the same signature, in this case TreeNode(string,TreeNode[]) :
public TreeNode( TreeNode[] children, string altData );
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
By the way, if you are going to be doing a lot with tree controls, you might look at the Infragistics tree control. It's a bit expensive, but it has a lot more flexibility than the Microsoft standard tree control.
- Bruce
BRCKCC
|
|
|
|
|
Dave thanks for the response, I'm not sure if this got sent to you b4 or not but here it is again...sorry if its duplicated...
So now I'm alittle confused...
I have the following code:
MyTreeNode class implementation
namespace MyName
{
internal class MyTreeNode : System.Windows.Forms.TreeNode
{
private string ExtraLabel;
public string InternalLabel
{
get
{
return ExtraLabel;
}
set
{
ExtraLabel=value;
}
}
internal MyTreeNode()
{
ExtraLabel=null;
}
}
}
Instanciation
MyTreeNode Node = (MyTreeNode)new TreeNode(Drive,IconIndex,IconIndex);
I get an invalid cast exception thrown...what am I doing wrong ?
|
|
|
|
|
I think it's going to be more like this:
MyTreeNode Node = New MyTreeNode( parameters );
And when you add it to the Nodes collection in your TreeView:
TreeView1.Nodes.Add( (TreeNode)MyTreeNode );
And when you try an access that node, say, in reference to the TreeView's SelectedNode property:
MyTreeNode myNode = (MyTreeNode)TreeView1.SelectedNode;
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well when I first created this class I tried your first suggestion;
<br />
MyTreeNode Node = new MyTreeNode(Drive, IconIndex,IconIndex);<br />
but it would not compile, I got an error indicating that no constructor for MyTreeNode took 3 parameters (which according to my class is true...My constructor takes 0 parameters). Hence my initial question about needing to create default consrtuctors in MyTreeNode class duplicating the base TreeNode Constructors. This is why I'm confused.
|
|
|
|
|
That's right, you have to supply your own constructor if your going to do this. The TreeNode class doesn't have a constructor that understands the parameters you gave it, so you have to supply one that takes those 3 parameters in your MyTreeNode class code, but you don't need to recreate the constructors of the base class, TreeNode. Just add you own contructor.
public MyTreeNode( string drive, Int32 iconIndex, Int32 iconIndex );
The Int32's should be whatever type your trying to pass into your constructor...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
ok, to recap:
I need to duplicate the base class's contructors in my inherited class's implementation if I use them in my inherited class.
If thats the case, and the TreeNode's constructor is suitable, then where does the following apply ?
Dave Kreskowiak wrote:
Since your extending the existing TreeNode class, all you have to do is supply your own constructor if one of the existing ones is not suitable.
|
|
|
|