|
Dave Sexton wrote: What scrolls to the top left corner? The form? The user control? The mouse pointer?
The form has autoscroll set to true and usercontrol to false so the form scrolls it seems. I tried to catch Form_Enter event and try to set scroll position to 0,0 of form but didn't work.
|
|
|
|
|
Hello, I am going to have a Windows Forms project start in a day or two that will need me to have an application that will be able to reset itself to its initial state if the database connection is lost. What I would like to do is to create the process so it contains 2 application domains - one (the child) where the bulk of the application will be running and another (the parent) which monitors the database connection and restarts the child appdomain if connectivity is lost. I also need the ability to send simple messages between the two appdomains.
I don't expect anyone to write any code for me, I just have had trouble finding concrete examples of how to do all this online and I would like someone to confirm whether I've got the general idea right or not. That being said, is this how you would do it:
1) Create two windows forms projects; the child and the parent. Set the parent as the starting project.
2) In the child application have a method something like:
public class Form1 {
public static Form1() StartApplication() {
Form1 f = new Form1();
}
}
3) The parent runs in the default application domain. When the parent is started, Create a new domain using d=AppDomain.CreateDomain("new domain"), load the executable created by the child project into it using d.Load(filename), and then use .NET remoting (which I still need to read up on) to call Form1.StartApplication()
4) Communicate between the domains using a .NET Remoting Channel (what is the best option for communicating between 2 appdomains in the same process?)
5) To restart the other domain call AppDomain.Unload(d), then create a new domain and load assembly as before.
I need to use certain proprietary controls in the application so I would prefer to keep with .NET 1.1 - if that poses any particular problems however I suppose it shouldn't be a tremendous amount of trouble to upgrade.
Once the project starts, I'm not going to have a lot of time to research and I don't have a Guru to go to so I put myself at your mercy. Am I missing anything here? Is this how you would do it? Is there any online tutorials you guys can recommend?
modified on Friday, May 9, 2008 9:53 AM
|
|
|
|
|
Why do you think you need two domains? You can have a single app with multiple threads (at least 2 in this case). One thread for the windows form to run in and another which will check the connection periodically. If connection is lost then re-initialize the application. This will make everything a lot simpler as you do not need to bother with remoting.
Let me know if I am missing something.
|
|
|
|
|
Well yes, there's a couple other issues. Essentially, in order to do this I would have to create another program which would have as its sole duty restarting the application, then when a 'restart' condition is detected I would have to start up the restarting program, shut down the actual application. Also, I would loose all ability to keep state information over how many times I have had to do this. Finally, there would be perceptible flicker as the application shuts down and restarts - that's unacceptable for the type of application that this is.
So yeah, while I understand why you would ask that, I've discussed the issue with several people and this was the simplest solution that we had. (The more complicated solution is to create a ResetRegistrar object that all objects register themselves with and that will call a Reset() method for each object when a reset condition is met).
|
|
|
|
|
Okay. In that case I suggest you use the Observer Pattern for your solution. Using this pattern everything should be pretty neat and somewhat easy to implement.
|
|
|
|
|
Yup, that's what I was thinking before this solution with application domains was proposed to me on the ALT.NET list. I thought it was pretty nifty and would give me an oppurtunity to learn something new. Are you saying that its not possible?
|
|
|
|
|
Togakangaroo wrote: Are you saying that its not possible?
Never said that.
Your app which is talking to db will be the observable and the restarter will be the observer using the observer pattern.
|
|
|
|
|
Hi all,
I have an urgent question. I have a WebService on the net that has such methods:
Client[] getClients();
Software[] getSoftwareByClientId(int clientId);
I made the code that populating the software DataBindingSource on CurrentChange event of the clients DataBindingSource. But i think it's not a nice solution because current item changed a lot. And it's calling the web service many times. Does anyone know some nice way to create custom DataSet wrapper for such WebService?
|
|
|
|
|
If you really need help then you should try to take some time in preparing your question so people can understand it. What do you mean, I quote you:
"I made the code that populating the software DataBindingSource on CurrentChange event of the clients DataBindingSource." Makes no sense.
1. First tell use what you want to do.
2. Then, tell us what you are doing.
3. Then, tell us what the problem is.
I will respond once you make your question more clear as I do not understand you right now.
|
|
|
|
|
<Root>
<Book>
<ID>A</ID>
<NAME>AA</NAME>
</Book>
<Book>
<ID>B</ID>
<NAME>BB</NAME>
</Book>
</Root>
I want to delete the parent node whose ID is "B" ... how can i do this ?? Thank you..
<Root>
<Book>
<ID>A</ID>
<NAME>AA</NAME>
</Book>
</Root>
|
|
|
|
|
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
xDoc.Load("<<give xml path here>>");
System.Xml.XmlElement xEle = (System.Xml.XmlElement)xDoc.DocumentElement.SelectSingleNode("//Book[ID = 'B']");
if (xEle != null)
{
xEle.ParentNode.RemoveChild(xEle);
}
I have not tested this should work
Check My other C# Posts
modified on Friday, May 9, 2008 10:24 AM
|
|
|
|
|
I am looking for a good method to keep my constants. Currently I have created a static class like this
public static class ConstantMessages
{
public static string ServerCommunicationFailure = "Message";
public static string AuthenticationFailure = "Message";
} I have many fields like this. Is this a good approach ? Or is there any alternative better approach for this ? I will be using the above class like the following
try
{
}
catch(Exception ex)
{
throw new CommunicationException(ConstantMessages.ServerCommunicationFailure);
}
|
|
|
|
|
I'd just use a settings class, that's what they are for. But, this does work just fine.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: But, this does work just fine.
Thanks. Yes this works fine, but it tough to maintain. Each time a variable and it's value has to be added. Settings class looks good, I will give a try. There is going to be many settings which will be kept in this settings file, do you think it will slow down the accessing ?
|
|
|
|
|
Looking at this example it looks like there is a contradiction of ideas here. The class is called ConstantMessages, but the strings inside the class are being set up so that the application can modify them. If you want constant messages why not use:
public const string ServerCommunicationFailure = "Message";
This should give a performance benefit.
If I am wrong, someone please correct me so I can continue to learn.
Kalvin
|
|
|
|
|
Yes you are correct. I wrote that to explain the problem. This is not used exactly as it is.
|
|
|
|
|
However, the recomended way by MS is to use static readonly instead of const.
because of versioning issues.
if you use a const, every consumer that use your const will have the const value compiled down into the consumer code.
while if you access a readonly field, the consumer code will always get the values from the owner class.
in short, if you use consts and then ship a new version of the dll containing your consts, those changes will not affect already compiled code.
while if you use readonly fields, it will affect already compiled consumers..
|
|
|
|
|
Very valid points. Thanks for that Roger
|
|
|
|
|
What?! I've never seen that documented anywhere.
But I just tried it and it seems to be true.
That doesn't make sense.
Edit:
It's true of enum members as well.
I just looked through the specs and saw no mention of this functionality, but I see now that it does make (some) sense.
Among other things, const values are valid in case labels, and case labels must be unique. Changing a const value (or enum ) could make a previously-compiled switch invalid.
So, yeah, I think a best practice is; unless the value is an actual constant value like Pi, don't use public const , but use public readonly instead. Using private const , may not be as bad, but the next developer to come along may make your private s public . So use const sparingly.
Thanks for the tip.
modified on Monday, May 12, 2008 11:46 AM
|
|
|
|
|
Use an enum with Description attributes?
enum Messages
{
[Description("Message")]
ServerCommunicationFailure
,
[Description("Message")]
AuthenticationFailure
}
|
|
|
|
|
Thanks. I will take a look into that.
|
|
|
|
|
Hello all,
I have an array of a simple object type:
class EntryPoint
{
private widgets[];
public EntryPoint()
{
this.widgets = new widgets[1000]
...code here to populate 1000 widgets...
}
public Widgets[]
{
get { return this.widgets; }
}
}
class widgets
{
public string key;
public string value;
}
Now, elsewhere in the the application, I need to be able to extract values from the widgets[] from instances of EntryPoint . However I need to be able to do this using the string key, not the index number. So the question is how can I do this? A hacking but slow way is something like this:
public string GetWidgetValue(string key)
{
string returnValue = null;
foreach(widget w in this.widgets)
{
if (w.Key == key)
{
returnValue = w.value;
break;
}
}
return returnValue;
}
This would work, however as mentioned enumerating through the array for every value request could prove to be slow. So can anybody give me an idea of what to do?
A perfect solution would be to encapsulate the base array with something like a StringDictionary and therefore do something like this:
EntryPoint ep = new EntryPoint();
string value = ep.Widgets["widgetkey"];
So the question is, how to do this?
Obviously the sample above is a simplified version of the question, in reality I am working with an array that is generated by deserialising an XML file into a class generated by the XSD tool. This means that unless I ditch XSD for something else (any suggestions?) I am stuck with integer indexed arrays.
modified on Friday, May 9, 2008 7:23 AM
|
|
|
|
|
Quick ? What sort of subject line is that ?
The obvious solution is a Dictionary, that's what they are for.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Quick ? What sort of subject line is that ?
An extremely poor one, my error - we all make them from time to time
Christian Graus wrote: The obvious solution is a Dictionary, that's what they are for.
Yes, however as mentioned in the original post, I am working with classes generated by the XSD tool. As such I need underpin the stringdictionary with the simple arrays this tool creates and keep the array and the dictionary in synchronisation as code adds, removes, edits values. Unfortunately this is where I am not sure where to go or what to do.
|
|
|
|
|
WEll, you really cannot lookup by string unless you build a container that works that way. Why not just build a dictionary at the point of deserialising the list, then use that for lookups ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|