|
zaboboa wrote: Hello,
I am loading a file within my app and the way I am refering to it is something like that:
this.richTextBox1.LoadFile("c:\\tmp\\Document.rtf");
However if I want to deploy the application on some other machine, obviously the file will not be there. So, if I want to include the file in my application how do I refer to the file then?
Thank you.
Is the file something you will deploy with your code? If so you will know where it should be. You could try something like this:
try
{
this.richTextBox1.LoadFile("c:\\tmp\\Document.rtf");
}
catch
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Please locate Document.rtf";
ofd.Filter = "RTF File|*.rft";
ofd.ShowDialog();
if ( ofd.FileName != "" ) { this.richTextBox1.LoadFile( ofd.FileName ); }
else {
}
|
|
|
|
|
You could put the .rtf file in the same directory as the .exe. You can access the startup path with:
AppDomain.CurrentDomain.SetupInfo.ApplicationBase
The application base is ALWAYS the location of the .exe, NOT the location you started the .exe from.
|
|
|
|
|
hi there!
i wrote a little application to demonstrate a little issue of mine.
just compile this source and check the memory used by the application (taskman or process-explorer)
the application starts with about 6mb memory.
when the last messagebox is displayed, everything should be disposed and the memory should return nearly to 6mb. but it doesn't.
has anyone any idea how to get the GC to collect this unused (but reserved?) memory?
i have to engineer a little application which will run on a terminalserver for each user. (50users x 10mb unneccessary memory is not very good...)
best regards
#code begin
using System;
using System.Windows.Forms;
namespace GCTest
{
///
/// Zusammenfassung für Class1.
///
class Class1 : Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private bool running = true;
private System.Collections.Hashtable mem;
///
/// Der Haupteinstiegspunkt für die Anwendung.
///
[STAThread]
static void Main(string[] args)
{
Class1 cl = new Class1();
Application.Run(cl);
MessageBox.Show(GC.GetGeneration(cl) + "","wait");
GC.Collect(2);
MessageBox.Show("wait","wait");
}
public Class1()
{
InitializeComponent();
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(Runner));
t.Start();
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 40);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "alloc";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(40, 80);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(152, 23);
this.button2.TabIndex = 0;
this.button2.Text = "set objects null";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(40, 120);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(152, 23);
this.button3.TabIndex = 0;
this.button3.Text = "set hashtable null";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(40, 160);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(152, 23);
this.button4.TabIndex = 0;
this.button4.Text = "exit";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// Class1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button3);
this.Controls.Add(this.button4);
this.Name = "Class1";
this.Text = "Bla";
this.ResumeLayout(false);
}
private void Runner()
{
while (running)
{
GC.Collect();
GC.WaitForPendingFinalizers();
System.Threading.Thread.Sleep(5000);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
mem = new System.Collections.Hashtable();
for (int i = 0; i < 1000000; i++)
mem.Add(i,new Consumer());
}
private void button2_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < mem.Count; i++)
mem[i] = null;
}
private void button3_Click(object sender, System.EventArgs e)
{
mem.Clear();
mem = null;
}
private void button4_Click(object sender, System.EventArgs e)
{
this.Close();
running = false;
}
}
public class Consumer
{
private string _str;
public Consumer()
{
_str = "abcdefghijklmnopqrst";
}
}
}
#code end
|
|
|
|
|
Stefan Fohringer wrote: the application starts with about 6mb memory.
when the last messagebox is displayed, everything should be disposed and the memory should return nearly to 6mb. but it doesn't.
has anyone any idea how to get the GC to collect this unused (but reserved?) memory?
i have to engineer a little application which will run on a terminalserver for each user. (50users x 10mb unneccessary memory is not very good...)
You're misunderstanding the way the memory model works. After the GC runs, memory from collected objects is placed in the application heap. It is not immediately returned to the OS, for the same reason that standard win32 apps don't (doing so involves a major performance hit from the context switch). Excess unused memory will be freed eventually under certain conditions, the ones I'm aware of are the app being minimized, the OS asking the app if it can do so (ie when the system needs more than is currently available), when the app has was the GC determines to be an excessive ammount. I'm not sure what the rules on this one are, but apps that breifly allocated hundreds of megs will rapidly return it following a GC. I don't know what size/time thresholds are involved here.
PS this comes up often enough it should probably be faqed somewhere.
|
|
|
|
|
The GC won't free the Reserved memory unless Windows asks for it back. GC keeps this reserve so it can quickly allocate memory for new objects. You can't specify how much and can't control how this reserved pool is managed in any way.
If you want to know how much memory your application is REALLY using, TaskManager is the worst possible place to go. For more accurate information, you need to use the .NET CLR counters in Performance Monitor.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
There are Win32 API calls you can call through PInvoke that will force windows to reclaim the memory that GC has reserved. There is something called "working set" that windows uses to manage memory usage for standard windows apps (primarily, those with a window...vs. a windows service for example. A quick test you can run is to check your apps memory usage when its a window, and check again after minimizing it...most probably, you'll see a change in memory usage, sometimes a significant change). You can force your application to free memory down to its minimum working set size, and you will see a change in your apps memory usage in Task Manager. Just be forwarned, this is NOT RECOMMENDED. As has already been mentioned, the GC tries to keep as much memory in reserve as it can for performance reasons. The GC is also a highly intelligent piece of code, and it will behave differently on different systems, and even on the same system in different conditions. Trying to "force the issue" in regards to freeing memory usually results in a loss, overall, in one way or another. Ultimately, the GC knows best, and you should let it do what it does.
-- modified at 22:34 Friday 4th November, 2005
Oops, replied to the wrong one. Apologies.
|
|
|
|
|
Jon Rista wrote: Just be forwarned, this is NOT RECOMMENDED.
That's why I don't tell anyone this. Nothing like giving someone the key to killing the performance of their app...
Jon Rista wrote: Oops, replied to the wrong one. Apologies.
;)
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well, there are times when its useful to use it. I don't know Stefan's situation in detail, and if he really does need it, its the only way to do what he needs. I don't think its my place to judge someones capabilities, and if places were reversed, I'd rather be given the knowledge than be keept in the dark by someone who doesn't know my skills or intents.
In Stefan Fohringer case, beeing that his application will be used in Terminal Services, it could very well be neccesary to have a higher degree of controll over his applications memory usage. There are numerous issues with .NET applications running under WTS where memory usage becomes a major issue. You can search the net for numerous blogs on the issue.
-- modified at 16:00 Saturday 5th November, 2005
|
|
|
|
|
Hello,
I wrote singe-threaded console application which goes through the list of IP addresses and quries them individually if they are up and running or not. Each run takes 20 s for non-responsive computer since it's default timeout of socket in Windows, becouse of that it takes 4 hours to run my application.
I want to optimize application with multi-threading features but since I never done it I'd welcome any pointers or good articles or code samples for that matter.
What I ultimitately would like to do is to have like 10-20 threads in pool and feed my list of IP addresses to that pool when thread finished executing I'd like to update global DataSet for applicaiton with results of quieries.
Thanks,
G
|
|
|
|
|
Why not just send a UDP broadcast, then listen for responses? You could then periodically scan the list of responders and mark any that haven't replied in some period of time as down. This would require a small 'responder' program in each node the listened to the 'are you up' query and replied with its own "i'm up" udp broadcast.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
|
|
|
|
|
Well, I did not fully specify requirement. I'm not acutally looking for servers being up or down but for SSL servers so I have to connect using TCPClient.
|
|
|
|
|
You can use the ThreadPool class provided by the .NET Framework, but it's not really recommended for executing long running operations (in the order of 20 seconds). You can find plenty of implementations for ThreadPools if you search around in CP. In any case, the idea is the same.
void YourMainFunc()
{
for (int i =0; i<listOfIPs.Length; ++i)
{
ThreadPool.QueueItem(ThreadFunc, listOfIPs[i]);
}
}
void ThreadFunc(string IP)
{
if (SuccessfulQuery(IP))
{
UpdateDataSet(IP);
}
}
void UpdateDataSet(IP)
{
lock(xyz)
{
}
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
what is "xyz" in lock function?
|
|
|
|
|
Any object, I put a lock statement just to indicate that the Dataset might be accessed by multiple threads, so you need to some kind of synchronization.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi,
How do i deal with the case of recovering communication between client and server if one of them has just restarted?
At the moment if I close my client (after succesful communication) and restart it, i can't communicate with my server, i have to close down the server and restart that too. What am i missing?
Any help greatly appreciated.
Thanks in advance
Duffs
|
|
|
|
|
For ASP.NET and the language?
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Is there an easy way of passing mouse events from a control to the form below in, e.g i have a label on the form and want any mouse events that happen on the label to be passed to the form underneath it.
I cant just disable the label (e.g. label.Enabled = false) as i still want the label to be able to respond to the events before the form.
My only idea is to send another message to the form when the label recives it, but this seems a little long winded.
Barry
|
|
|
|
|
wheelerbarry wrote: My only idea is to send another message to the form when the label recives it, but this seems a little long winded.
And it's the only way to do it. Mouse clicks will not go to all (or selected) windows beneath the spot where the mouse was. You actually have to create a new mouse message and manually send it to the windows you want. For this, you'll have to have the window's handle (hWnd).
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How can I have my richtextbox accept a tab correctly?curently when I press the tab key, it does not do anything .
thanks
regards paula
|
|
|
|
|
Why not try the AcceptsTab property?
Regards,
mav
|
|
|
|
|
i need help plz
i want to open web Page in my program without use internet Explorer
Just by using my program and Set value to textbox and then Push Submit button
after taht i will have sisson from this site , i want to access another page inthe site and make check to CheckBox
Ex:
i want my program to open http://www.mysite.com/login.aspx
and set user name & password to textbox in the login page and push SUBMIT button
then i will have sisson from this site to assecc http://www.mysite.com/myacount.aspx
i want to make check to checkbox in this page
-----------------------------------------------------------
Palestine
|
|
|
|
|
|
You'll need to create your parameters and handle your response...and I'm guessing you are POSTing...
private string GetResponse(string URI, string Parameters)
{
WebRequest webRequest = WebRequest.Create(URI);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
// data
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
webRequest.ContentLength = bytes.Length;
Stream os = webRequest.GetRequestStream();
os.Write (bytes, 0, bytes.Length);
os.Close ();
// response
WebResponse webResponse = webRequest.GetResponse();
Stream s = webResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(s);
return streamReader.ReadToEnd().Trim();
}
Hope this helps!
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Hello!
I have a windows form that, by use of a menu, opens another window (not an MDI child). When I close this new window, the form also closes. How can I prevent this from hapenning?
Thank you,
Patrícia Gonçalves
|
|
|
|
|
You can try with a modal window...
<br />
Form1 form = new Form1;<br />
form.ShowDialog();<br />
try this..
hope it helps ^^
|
|
|
|