|
HalliHaida wrote: grp = Graphics.FromImage(image);
you create a graphics (which is an expensive object) and you don't dispose it. That is your problem.
Now why are you creating a new bitmap and a new graphics all the time. You could probably work with just one each, and reuse it over and over, reducing the load caused by your app.
BTW: why do you use axWebBrowser instead of WebBrowser class?
|
|
|
|
|
As well as what Luc has said, there is a potential that the pages you navigate to cause a leak in IE as well. Basically, IE uses reference counting to control when things get collected by the internal IE garbage collector. Certain things, such as unreleased event handlers and badly implemented closures, leave references in the reference counter, so these items never get removed (even if the page is refreshed).
|
|
|
|
|
Thanks a lot for the information.
|
|
|
|
|
|
If what you are saying is that say your KVP list contains:
K1, AAA
K2, BBB
K3, BBB
K4, CCC Then your strings list should only contain 3 elements: "AAA", "BBB", and "CCC", then you need to:
1) Change your array of strings to a List<string> as you don't know how many elements it will contain - you can convert it to an array later if you need to with the ToArray method.
2) Set a string lastValue and set it to the first value, plus the string "Do not match" - this ensures that the first KVP value is transferred to the new list.
3) In your loop, compare the current KVP value to lastValue and if different, use the Add method to add it to your List of strings.
4) At the bottom of your loop, set lastValue to the KVP Value.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I think this pattern is what you are looking for:
using System;
using System.Collections.Generic;
namespace KeyValuePair
{
class Program
{
static void Main(string[] args)
{
List<KeyValuePair<string, string>> listImport = new List<KeyValuePair<string, string>>();
listImport.Add(new KeyValuePair<string, string>("K1", "CCC"));
listImport.Add(new KeyValuePair<string, string>("K2", "BBB"));
listImport.Add(new KeyValuePair<string, string>("K3", "AAA"));
listImport.Add(new KeyValuePair<string, string>("K4", "BBB"));
listImport.Sort(delegate(KeyValuePair<string, string> first, KeyValuePair<string, string> second)
{
return first.Value.CompareTo(second.Value);
});
string strLast = String.Empty;
List<string> listDistinct = new List<string>();
foreach (KeyValuePair<string, string> kvp in listImport)
{
if (strLast == kvp.Value)
continue;
listDistinct.Add(kvp.Value);
strLast = kvp.Value;
}
foreach (string str in listDistinct)
Console.WriteLine(str);
Console.ReadKey();
}
}
}
|
|
|
|
|
Hi ,
I am submitting a html form in ASP.NET 1.1, to a websphere server. I am browsing excel file and submitting through object to Websphere server, by sybmitting form with action as Websphere hosted address.
Whenever I login to app, and try to upload the file with above functionality, for the first time, I get redirected to Login.aspx automatically. But when I re-login again and does the same thing as above, the file is uploaded successfully.
Can you please help me regarding this, as I have maintained releative values of timeout for session and form-authentication in web.config file.
- Ajay K
modified on Tuesday, October 19, 2010 3:43 AM
|
|
|
|
|
Please try the ASP.NET forum - this is C#
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
hi, I heard that there is a method of using class to get the value from form 1 to form 2 but i not familiar with using class.So is there any advice or reference that you could provide me?
|
|
|
|
|
Hi,
you should read a book about c# and object oriented programming. Here is a solution, but I really think you should read about it so that you can understand it:
Create a form "Form2" in (e.g. in the designer) and use this code in your code behind file (e.g. Form2.cs)
public class Form2 : Form
{
private int m_nValue = 0;
public Form2()
{
}
public void SetValue(int val)
{
m_nValue = val;
}
}
then you can call the public function in your Form1:
Form2 frm = new Form2();
frm.SetValue(1);
|
|
|
|
|
I guess it would be a shared (static) class with a public property that is exposed to the outside world.
If one form has a reference to the other forn, I'd rather use a property within the other form.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Beside the other suggestions you could also just add a constructor to your 2nd form (that you call from your first form) that takes the class of your choice as an argument.
internal class Form2 : Form
{
internal Form2(MyClass obj)
{
MessageBox.Show (obj.Name + " " + obj.Number);
}
}
internal class MyClass
{
internal string Name
{ get; set; }
internal int Number
{ get; set; }
}
In Form1 you call:
MyClass myC = new MyClass();
myC.Name = "John Doe";
myC.Number = 42;
Form2 f2 = new Form2(myC);
f2.Show();
|
|
|
|
|
if i want to get the value of form2 textbox1 to form1 textbox2 what code should i create??
|
|
|
|
|
If you opened Form2 from Form1 , and want to add the value of Form2.textbox1 to form1.textbox2 I would do this using delegates .
Check out this[^]link (Second Scenario) which explains it. Good luck
|
|
|
|
|
|
You can also try making a property as static for FORM1 and then add the reference of FORM1 in FORM2 then with the class name in which you have defined/declared the property as static; you can easily get it by Class Name.
|
|
|
|
|
Not a good idea - there are several much better ways to do this than using static. Consider the same problem when using non-Form related classes: If you use your static solution what happens when there are two instances? What happens when multiple threads are involved?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Best Solution: Learn how to program in .NET and OOP. (This is quite a basic problem, I think you didn't understand the concept of instances, scope, access modifiers etc.)
2nd Solution: Follow the advices here (but don't follow the "make a static property" advice!)
Dirty Solution: Just declare your TextBoxes as "public" (you can set the "Modifier" in the VS-Designer).
I'd head for the "best solution" - learn your basics. This will really help you!
|
|
|
|
|
Explain in more detail how Form 1 is related to Form 2. How are each instantiated? In what order are they displayed? Is it always the same or does this change?
|
|
|
|
|
Hi (im German so please forgive my bad english),
I wrote a c# .net 4.0 Program that gives me results from different calculations into different variables with different datatypes (myInt, myDouble, myString, myBool, myWhatevr)
Now i wanted to give al this results to my xml file that is used as a logfile.
This is my xml code:
using System;
using System.Xml;
namespace xml_exporter
{
public class xml_tool
{
public static void tel_toXML()
{
string dateTime = DateTime.Now.ToString("yyyyMMddhhmmss");
XmlTextWriter myXmlTextWriter = new XmlTextWriter("C:\\XML-Log_" + dateTime + ".xml", System.Text.Encoding.UTF8);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument(true);
myXmlTextWriter.WriteStartElement("Data");
myXmlTextWriter.WriteComment("Start");
myXmlTextWriter.WriteElementString("Farbe", "Blau");
myXmlTextWriter.WriteElementString("Struktur:", "Rau");
myXmlTextWriter.WriteComment("Farbnummer" "");
myXmlTextWriter.WriteElementString("Dichte", "");
myXmlTextWriter.WriteElementString("Name", "");
myXmlTextWriter.WriteElementString("Aktiv", "");
myXmlTextWriter.WriteComment("End");
myXmlTextWriter.WriteEndElement();
myXmlTextWriter.Flush();
myXmlTextWriter.Close();
}
}
}
Now i want to know how to give my variabel values to the xml construct!?
so that the xml-file should look "like" this:
Colornumber ValueOfmyInt variable Colornumber <br />
..<br />
Dichte 5.4 Dichte
etc.
However I searched in the c# openbook, msdn I didnt found the right answer to my problem. And there must be a Code or a Command to give the values of my variable to the XML thing.
I'm just always finding "how to read from xml" and stuff but thats not the same I think. Im still trying to build something up but its not working.
Ich flehe um Hilfe!
Does anyone have an idea how i can realise this ? Or a Link for exact this problem etc.? It would be a very big help for me.
greetz,
Sal
|
|
|
|
|
You want to write the value of some variables to XML? Did you scan the list of methods XmlTextWriter offers, in particular the ones that start with Write?
|
|
|
|
|
yes but maybe i understood it wrong. i thought write writes the file to a path not a variable to xml element.
ok worked for things like
Int32 = myInt = 3;
and then inserted the line : myInt.ToString()
so from now on the value is sended to the xml element.
thanks
modified on Monday, October 18, 2010 10:26 PM
|
|
|
|
|
Luc has already given you the answer, see here[^].
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hi,
I'm trying to dial phone number and using SerialPort control for this, which is initialized with my USB modem.
SerialPort serialPort1 = new SerialPort("COM5", 115200, Parity.None, 8, StopBits.One);
serialPort1.Open();
serialPort1.Write("ATDmyphone\r");
serialPort1.Write("ATH\r");
serialPort1.Close();
everything works except 1 thing - there is no sound from the modem.
I tried to use ATM2 and ATL3 commands before I start to dial - but there was still no sound. But when I create dial-up network connection, and dial from its dialer - there is a sound.
What am I missing here?
thanks!
|
|
|
|
|
Are you sure it isn't just dialing pulse? That can be harder to hear than tone. You should use ATDT just to make sure.
|
|
|
|