|
Tracing is fine as long as you implement it correctly (but still will never give the sort of state information debugging can). As I mentioned in my previous post, make sure you actually have trace listeners installed that will work correctly. The DefaultTraceListener won't work since debugging messages are sent only to the local computer (though remote debugging services may dispatch them elsewhere - I honestedly never tried this approach). You could always write your own TraceListener derivative that sends messages using MSMQ, Web Services, or some other standard or proprietary mechanism.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've got a memory issue with an unmanaged call to GDI.
I've followed the CreateDC, releaseDC, DeleteDC step outlined in the platform SDK,these methods all return true or 1, indicating that they succeeded. However after each call to the method it consumes 3 mb of RAM and does not release the memory, the issue is that method will be called many times and builds up to about 60mb memory used.
I store a bitmap in a member variable, which i dispose of.
iWidth = nWidth;
iHeight = nHeight;
hdcSrc = User32.GetWindowDC(User32.GetDesktopWindow());
hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc,iWidth,iHeight);
image = new Bitmap(iWidth,iHeight);
GDI32.SelectObject(hdcDest,hBitmap);
GDI32.BitBlt(hdcDest,0,0,iWidth,iHeight,hdcSrc,iStartX,iStartY,SRCCOPY);
image = Image.FromHbitmap(new IntPtr(hBitmap));
User32.ReleaseDC(User32.GetDesktopWindow(),hdcSrc);
GDI32.DeleteDC(hdcDest);
GDI32.DeleteObject(hBitmap);
if I call GC.Collect() it clears the memory and brings it back down but this is oviously not a good idea.
Any Idea's?
|
|
|
|
|
nEgAtIvE cReEp wrote:
if I call GC.Collect() it clears the memory and brings it back down but this is oviously not a good idea
That should be your clue right there. Unmanaged resources are called "unmanaged" because they are not managed by the GC. If you call GC.Collect and it makes a difference, then unmanaged reosurces are not your problem.
The problem here is that you must dispose those images you're creating (the image ) variable. When finished (and be re-assigning image to something else), call image.Dispose() ; otherwise, the Image is not cleaned-up until the GC gets around to it or you call GC.Collect .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the reply.
I do dispose of the image variable, I just didn't include the code on the post. Although I realize my comment on the GC doesn't make sense.
I will have to investigate if any .NET objects are still hanging around, that acompany the Call to GDI) i.e the form.
thanks again
|
|
|
|
|
I'm working on the hex conversion software for myself and engineering use. I'm trying to get the int value of oxFFFFFFFFFFFFFFFF as the windows XP calculator can figure this.
I'm ok for 15 characters long in Hex but not 16.
I have been getting the result of -1 dec value.
What I did was doing by:
(note that the editbox in windows application are: edtHex (editbox for Hex values) and edtDec (editbox for Dec))
long tempDec;
tempDec = long.Parse(this.edtHex.Text, System.Globalization.NumberStyles.HexNumber);
edtDec.Text = tempDec;
Anyone have any suggestion on how I can correct this?
Am I correct that this "long" is 64bit in XP?
|
|
|
|
|
A long (C# alias for Int64 ) is 64 bits on any platform.
16 F's for a long is -1. 16 F's for a ulong , however, is 18,446,744,073,709,551,615. It's important to understand the difference between signed (like int and long ) and unsigned (like uint and ulong ) types: signed can be negative, and a negative value is when the most significant bit is 1.
It's also important to note that unsigned primatives are not CLS-compliant, meaning that only CLS-compliant languages (i.e., no additional support for the CLI) like JScript.NET cannot use them. Both C# and VB.NET support unsigned types, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I dont even know if this is possible , but...
The company i work for uses 802.11x for wireless authentication. We have an issue regularly where the certificates expire or become invalid, because usually because the user has changed their password recently, and a bug in Microsoft's software causes it to fail on the automated request.
What i am looking to do is create a web page that will sit on our intranet that will allow users to request a new certificate based on who they are. We currently have to walk the user through going into MMC and walking through the certificate request procedure.
This is particularly timely since we had an issue recently that expired every certificate on the network....
i do know there is a certificate namespace, and since MMC allows for the request, there MUST be a way to use the object for this procedure, I am just at a loss where to start tocreate a page for it.
_________________________________________
Yes, I am the highly suggestable type.
|
|
|
|
|
Microsoft Certificate Services actually already has this functionality, and you can set up a CA site easily. I suggest you read the product documentation for Microsoft Certificate Services. I set up such a site with very few steps some time back on our network and it was quite easy, but I don't remember all that I did.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm trying to replace some text in an html file based on some regular expressions (or literal text) in a text file.
What should happen is that "A0-1234" in the html file should get replaced by:
"<a href="javascript:selectItem('A0-1234',42)">A0-1234</a>"
and "B1-123456" in the html file should get replaced by:
"<a href="javascript:selectItem('B1-123456',42)">B1-123456</a>"
and so on...
Here's what I'm doing:
static void Main(string[] args)
{
/* For following code:
* i - input; c - config; o - output;
* Therefore, isr - input streamreader, csr - config streamreader,
* cline - config line, iline - input line
*/
String ifile = "data.html";
String cfile = "config.txt"
String ofile = "newdata.html"; // output file name
string cline;
string iline="";
try
{
// open a StreamReader to read in the input file
using (StreamReader isr = new StreamReader(ifile))
{
// Read in the entire input file into a single string
iline = isr.ReadToEnd();
// open another StreamReader to read in the config file
using (StreamReader csr = new StreamReader(cfile))
{
// open a StreamWriter to write out to the output file
using (StreamWriter sw = new StreamWriter(ofile))
{
// Read in the config file, one line at a time.
// Each line corresponds to an expression to be matched
// in the input file
while ((cline = csr.ReadLine()) != null)
{
// Set every line of the config file as the
// regular expression to be tested for
Regex testExp = new Regex( cline );
/*
// Setup the replacement string
// INSTEAD OF cline, USE MATCHED VALUE
string replaceString = "<a href=\"javascript:selectItem(\'" + cline + "\',42)\">" + cline + "</a>";
*/
if (iline != null)
{
// Replace all matched expressions with the
// appropriate function
Match m = Regex.Match( iline, cline );
String replaceString = "<a href=\"javascript:selectItem(\'" + m.ToString() + "\',42)\">" + m.ToString() + "</a>";
m = m.NextMatch();
iline = testExp.Replace( iline, replaceString );
Console.WriteLine(iline);
}// end if iline
} // end while cline
// Write the replaced text back to the output file
// using the StreamWriter
sw.Write(iline);
} // end using streamwriter sw
} // end using StreamReader csr
} // end using StreamReader isr
} // End Try block
catch (Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
} // End catch block
} // End Main
Now the problem is that ALL matches of a regular expression in the config file (say "[A-Z,a-z]\d-\d{4,8}", which matches "A0-1234", "B6-12345678", "D4-12345" etc) get replaced by the first match...
So if the first expr matched in the input html file is "A0-1234", then all other expressions in the html file get replaced by :
"<a href="javascript:selectItem('A0-1234',42)">A0-1234</a>"
even if those expressions are "B4-12345", "T6-886745" or anything else that matches "[A-Z,a-z]\d-\d{4,8}"
Please help.....
|
|
|
|
|
Hy everyone!
I was just having a look how to get the cursor postion.
Because I do want a context menu pop up at the cursor position.
I did the contextmenu, but I didn't manage to make it appear!
My contextmenu looks like this:
System.Windows.Forms.ContextMenu ctNameKeyMenu;
ctNameKeyMenu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem menuItem1;
menuItem1 = new System.Windows.Forms.MenuItem();
System.Windows.Forms.MenuItem menuItem2;
menuItem2=new System.Windows.Forms.MenuItem();
ctNameKeyMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {menuItem1, menuItem2});
menuItem1.Index=0;
menuItem1.Text=ltemparray[1].ToString();
menuItem2.Index=1;
menuItem2.Text=ltemparray[2].ToString();
// show the contextmenu at the local mouseposition
ctNameKeyMenu.Show(lTextBox, ???);
lTextBox in the line above is the TextBox the contextmenu should appear for respectively appear in. I do know I have to put a point object in there as the second parameter. But well how do I get the MousePos?? Because I can't simply type MousePos() in there!
Thanks!
Stephan.
|
|
|
|
|
Cursor.Position should give you the mouse position I believe
|
|
|
|
|
Yup, I had this one, but the result was quit strange, because the context appeared around as far from the cursor as the cursor was located rom the upper left corner of my application window! Meaning the upper left corner of the context was twice the distance of the mouse distance of the left corner of the application.
Do you have an idea why?
Because I also tried Control.MousePosition.
Same result!
Because I can't find out why!
And a second question: When selecting one of the MenuItems I do want the selected one to being placed in the TextBox the Context "belongs" to. But to do so, I do have to create an eventhandler for the clickevent, but then I do loose access to my TextBox.
Well it looks like this:
....
System.Windows.Forms.ContextMenu ctNameKeyMenu;
ctNameKeyMenu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem menuItem1;
menuItem1 = new System.Windows.Forms.MenuItem();
System.Windows.Forms.MenuItem menuItem2;
menuItem2=new System.Windows.Forms.MenuItem();
ctNameKeyMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {menuItem1, menuItem2});
menuItem1.Index=0;
menuItem1.Text=ltemparray[1].ToString();
menuItem1.Click += new System.EventHandler(this.menuItem1_Click();
menuItem2.Index=1;
menuItem2.Text=ltemparray[2].ToString();
menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
ctNameKeyMenu.Show(lTextBox, Control.MousePosition);
.....
// same for menuItem2
private void menuItem1_Click(object sender, System.EventArgs e)
{
// assign the selected item of the context to the TextBox
}
But in the Clickevent section my TextBox is no longer accessible. So how do I get it in there? The selected item is available in the sender object, but this doesn't really help much.
Thanks again!
Stephan.
|
|
|
|
|
If you would read the documentation for the Cursor.Position property in the .NET Framework SDK, you'd see that the coordinate it in screen coordinates, so you must call PointToClient on the Control for which you want to transform the coordinates (relative to the Control ), passing the Cursor.Position to get a Point relative to the control:
Point p = button1.PointToClient(Cursor.Position);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks the hint worked!
Well I read this section, but I didn't count my application to be the client to the screen! But looking at it now, it looks clear and I am wondering why I didn't realize it earlier!
So then I can switch my task towards the event which has to take place when selecting an item in the context, namely assining it to the TextBox.
Thanks again!
Stephan.
|
|
|
|
|
|
If you want the algorithms supported by the CryptoAPI, then you'll have to P/Invoke a lot of CryptoAPI function and define lots of structs and consts to do it; otherwise, you can build an MC++ assembly without going to all that work. Either way, CryptEnumProviders is what you want to call, but this only enumerates CSPs supported by the CryptoAPI - not by .NET (which only encapsulates the standard CSPs). In addition, CSPs can be added using the <cryptographySettings> element which isn't used by an IConfigurationSectionHandler (technicall, the IgnoreSectionHandler is configured for that section) that you can use to query what's been added. CSPs can also be used without being registered in this way, like a TwoFish implementation I saw some time back.
The point is that there is not a single way to get what CSPs are available.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I am using service written by somebody else. I want to do some modifications in that. When I did modifications, I am seeing that service is stopping immediately. Do any body this kind of exp?? I am not getting any compile time or run time errors...
What is the reason for this.
Regards,
Satya
|
|
|
|
|
Where is the application stopping? Have you tried setting break points? Are any errors being thrown?
|
|
|
|
|
Hey everyone. Thanks in advance for any help. I have a WIN32 application that I am having difficulties with.
I basically have an ADD button for which you are able to add checkboxes at runtime. Then, I also have a REMOVE button which removes any checkboxes that are checked when the button is pressed. My difficulty lies in how to reference the checkboxes because they are all created at runtime. Here is some of my code.
<br />
function (int currentnumber) {<br />
<tab>myCheckBox = new System.Windows.Forms.CheckBox();<br />
this.panel1.Controls.Add(myCheckBox);<br />
myCheckBox.Location = new System.Drawing.Point(this.Group_label.Left-30, ystarter+(currentNumber*distance));<br />
myCheckBox.Name = "checkBox"+currentNumber;<br />
Console.WriteLine(myCheckBox.Name);<br />
myCheckBox.Size = new System.Drawing.Size(16, 24);<br />
myCheckBox.TabIndex = 6;<br />
}<br />
<br />
private void Remove_Group_Click(object sender, System.EventArgs e) {<br />
for(int i=1;i<=totalGroups;i++) { <br />
if (checkBox"+i.Checked == true) {<br />
this.panel1.Controls.Remove(checkBox"+i);<br />
}<br />
}<br />
}<br />
My REMOVE button click handler does not work properly. I can't get it to compile because it says that checkBox+i is not a valid Checkbox.
How do I reference my checkboxes that were created at runtime whose names should be:
checkBox1,checkBox2,....
Thanks again for any help.
|
|
|
|
|
That's not a valid variable name. You must enumerate your Controls and find a CheckBox with that name:
private Control GetControl(string name, bool caseInsensitive)
{
if (name == null) throw new ArgumentNullException("name");
foreach (Control c in Controls)
if (string.Compare(name, c.Name, caseInsensitive) == 0) return c;
return null;
} This returns a reference to a Control , so you can use the is statement to easily determine if it's a checkbox, or just recode the sample above to enumerate all Control s but in the conditional additionally use is to check if it's a CheckBox . Don't change Control c to CheckBox c (or something) because any control that is not a CheckBox will not cast and an exception will be thrown when enumerating.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can someone tell me what is wrong with this code.
I've got a couple of custom controls in a groupbox that i need to dispose. I tried the following foreach loop, but i get the error "Specified cast not valid".
foreach (WorkersCtrl c in groupBox.Controls)
{
c.dispose();
}
Thanks.
|
|
|
|
|
But that's very simple: at least one of the Control s in groupBox.Controls is not a WorkersCtrl .
The Controls collection holds Control s or derived classes, not limited to WorkersCtrl only.
If you really only want to call Dispose() then change WorkersCtrl c into Control c and you'll be fine.
mav
|
|
|
|
|
Thanks, it was pretty stupid of me. I've got it working now.
|
|
|
|
|
You must have a control inside the groupbox that is not of or inherit from WorkersCtl. You could try a couple of different things. You could either throw an if statement in there, to determine if the object is of type WorkersCtrl, and just use the object base class inside your for each decleration. Or...., you could change workersctrl to object, and set a debug statement within the foreach statement, outputing each objects .gettype().tostring() to determine which object is throwing the invalid cast error.
|
|
|
|
|
Hi all,
I have a problem concerning Crystal Report's performance on Win2000.
I use datasets to push data into my report, but the assignment of the datasource to the report and the the creation of the report take way too much time on some Win2000 systems.
Here are the two code snippets that take so much time:
report.SetDataSource(dataSet);
ReportForm reportForm = new ReportForm(report, m_ResourceManager);
reportForm.Show()
Some examples of the performance of this code:
On my Windows XP:
SetDataSource: 3 seconds
show report: 2 seconds
A colleague's Win 2000:
SetDataSource: 2 seconds
show report: 2 seconds
Another colleague's Win 2000:
SetDataSource: 105 seconds
show report: 391 seconds
My application runs fine on every Windows XP that I tested and it also runs fine on some Win2000 systems.
But unfortunately there are some Win2000 systems that have very bad performance running my app.
I have no clue what could be the reason for this.
For example:
The Win2000 system's load is at about zero percent, when it is waiting for the SetDataSource method to return.
How can this be?
Any help appreciated.
Best regards
Bernd R.
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|