|
After how many requests do you start getting NullReferenceException s? Just getting responses async without any checks is dangerous. There may be a limit and there are warnings about this in the .NET Framework SDK documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Well after about 20 hours of trying every possible combination, I found out a way around this. All my requests/responses are in the main thread and I close the HttpWebResponse and the response stream as soon as I get them and I am fine. I managed to first make an initial request which gives a webpage with about 50 links. I make the 50 requests/responses on these links and this works fine. I thought I was good until I tried to repeat the process and it gives me this exception. I dont' get it since I close all the streams and all the async calls return fine. All my HttpWebResponse/Request objects are local variables in a function so they are never reused. When looking at the threads when this exception is thrown I notice that there are two threads that are blocked waiting to read the response stream, ie.
private void ProcessResponse(System.IAsyncResult state){<br />
HttpWebResponse linkpage=(HttpWebResponse)((HttpWebRequest)state.AsyncState ).EndGetResponse(state);<br />
StreamReader stream = new StreamReader(response.GetResponseStream());<br />
string info = stream.ReadtoEnd();
stream.Close()<br />
response.Close();
You said that getting them without checks is dangerous. What do you mean by a check?
|
|
|
|
|
Well, I see one problem: what if the file is not simply a text file? It will not have an EOF (end of file) so StreamReader.ReadToEnd will never return. Even streams that may appear as text may not be, and may not have an EOF. Just use a Stream and buffer the output (you don't have to do anything with it, like you're not doing for string info ).
What I mean is that creating threads wildly like this - without limiting how many threads are created - is dangerous. You should either have some mechanism that counts the number of async requests and blocks at a certain limit. An even better way is to not using async calls but to instead use a ThreadPool and queue requests synchronously (the end result is still asynchronous). The ThreadPool limits the number of concurrent worker items (threads) and queues the rest. It also has a few additional benefits you can learn by reading about the ThreadPool class in the .NET Framework SDK documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I am drawing the tab control myself and here is the problem:
In the app the user is allowed to change the tab name. However, if the string he/she enters is too long, not all of it is displayed on the tab label. Here is the code I am using:
<br />
private void buttonsTab_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)<br />
{<br />
Font f;<br />
Brush foreBrush;<br />
<br />
f = new Font(e.Font, FontStyle.Italic | FontStyle.Bold);<br />
foreBrush = Brushes.Black;<br />
<br />
string tabName = this.buttonsTab.TabPages[e.Index].Text;<br />
StringFormat sf = new StringFormat();<br />
sf.Alignment = StringAlignment.Center;<br />
Rectangle r = e.Bounds;<br />
r = new Rectangle(r.X, r.Y + 3, r.Width, (int)f.GetHeight() + 2);<br />
e.Graphics.DrawString(tabName, f, foreBrush, r, sf);<br />
}<br />
I set the height of the rectangle I use in DrawString to the font height. I dont want the string to wrap and start on a new line.
Is there anyway that I can ensure that the entire string is displayed at once?
Is my only option to limit how long the new name that the user enters can be?
Thanx for the help
-Flack
|
|
|
|
|
StringFormat allows various ways of clipping your string. Dig around there
|
|
|
|
|
I looked at StringFormat but it didn't solve the problem. I could clip the string but I would rather the tab label width increase to allow for the whole string.
When I let the tab control draw itself, the tab label width is automatically set to an approproate width so that it can contain the entire label.
Is there any way for me to change the tab label size myself?
I use e.Bounds from the System.Windows.Forms.DrawItemEventArgs arg to the DrawItem function but for some reason the width is not large enough.
Does anyone have an idea as to how the tab control draws itself to allow for the whole string to be seen so that I can use similar code in my DrawItem method?
Any suggestions?
-Flack
|
|
|
|
|
The TabControl encapsulates the Tab common control, so you can P/Invoke SendMessage to send the TCM_SETITEMSIZE (0x1329) to the control (use its Handle property, which is the HWND for the control).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I would like to override the default .NET OpenFileDialog to add a text box and label, and then be able to retrieve the entered value via the properties of the overriden dialog.
Is this even possible, if so can anybody point me in the direction of any docs that could help me achieve this effect.
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
Inheriate from the OpenFileDialog, and alter the visuall aperance of the windows by resizing the window and adding your controls.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Yeah - that doesn't work. OpenFileDialog uses the OPENFILENAME struct (documented in the Platform SDK). This can accept a dialog template as a field (requires a mask). Extending this simply won't work. Any experience with native Win32 programming would tell you that, as well as knowing that most everything Windows Forms merely encapsulates native functionality, like the GetOpenFileName API that the OpenFileDialog uses. See the IL using ildasm.exe for that class and you'll see.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Forget what he told you - it won't work. The OpenFileDialog class uses the GetOpenFileName native API, which uses a OPENFILENAME struct. This can accept a dialog template, but this is a native resource and not reproducable (not without direct memory manipulation, which would require an unsafe context and experience with dialog templates) using purely managed code.
I recommend using a mixed-mode Managed C++ assembly in order to create the dialog template using the visual designer (not a Windows form - an "old school" dialog).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'am sorry for missleading you then.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Hello everyone,
how do I save and print a graphic created by GDI+, using C#?
I just want to save and print the graphic not including the form where graphic was drawn.
Thank!!!
|
|
|
|
|
This is how you save something. Lets just say the class UI is the user control that you want to save. Printing is a bit more complicated. I gotta go now, but if I come back and nobody has answered I will show you.
public class UI:System.Windows.Forms.UserControl<br />
{<br />
public void UI_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<br />
{<br />
} <br />
public event PaintEventHandler paint = new PaintEventHandler(UI_Paint);<br />
public void Save()<br />
{<br />
<br />
Bitmap b = new Bitmap(this.Width,this.Height,this.CreateGraphics());<br />
PaintEventArgs pe = new PaintEventArgs(Graphics.FromImage(b),this.ClientRectangle);<br />
paint(this,pe);<br />
b.Save("filename",System.Drawing.Imaging.ImageFormat.Jpeg);<br />
}<br />
}<br />
}
You can save it to any format you want, there are quite a few you can pull from ImageFormat.
|
|
|
|
|
I'm trying to upload very large files to an image datatype in SQL Server 2000 using a c# app. The necessary code is below:
FileStream fsFile = new FileStream(chkLstFiles.Items[x].ToString(), FileMode.Open, FileAccess.Read); <br />
Byte[] fileData = new Byte[fsFile.Length]; <br />
fsFile.Read(fileData, 0, fileData.Length);
The code works fine for 'small' files (Under 40mb), but after that it fails. The error returned is, "Insufficient system resources exist to complete the requested service." It is choking on the fsFile.Read line. If I split that out to individual lines like:
fsFile.Read(fileData, 0, 10000000); <br />
fsFile.Read(fileData, 10000001, 20000000); <br />
...
It will continue until it passes into the 40-50million reads. (That's where I get the 'Under 40mb' limit above)
Ideas, thoughts or tips? Thanks in advance!
|
|
|
|
|
No databases has been designed for this. File systems has been design for this. Save a link to the location in the record and save the file where it belongs.
|
|
|
|
|
leppie wrote:
No databases has been designed for this
Oracle can accept file this large. A database vendor I used to program systems for actually had a scheme where they'd sit their database file (multi-gigabyte) inside an oracle database and access their own datastores through the oracle database. I never tried it, but they claimed that if you tweaked Oracle just right you would get faster access to the data sitting in their datastore files, and the client's DBAs would only need to worry about backing up one database.
If you were wondering why not just use Oracle directly the answer was that one of this database vendors specialities was the concept of "long transactions" - A short transaction is one that is complete in a fraction of a second, or maybe a few minutes at the very most (SQL Server and Oracle are very good at those). A long transaction is one that can take potentially years to complete.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
When I am using Microsoft Web Browser, I want to take the data that sending by "Microsoft Web Browser". But, when I trigger the BeforeNavigate2 event successfully. I can't get the post data or headers.
private void axWebBrowser1_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
MessageBox.Show(e.postData.ToString());
}
It doesn't work. Is any body know the reason or how to solve this problem.
Thanks
|
|
|
|
|
I would like to pass a public integer variable from a C#.Net Win Form to another C#.Net Win Form within the same project. I use the get{}; set{}; acessor or a global struct (is this available in C#? Maybe only available in C++).
I am thinking that maybe I should pass by reference instead of pass by value.
There is so much difference between SDK Compiler code, and Visual Studio Win Form code, I am really kind of lost right at the moment.
|
|
|
|
|
Please don't take my response the wrong way, I am trying to help by finding out what you are trying to achieve, however your initial posting is somewhat vague.
kd7gim wrote:
I would like to pass a public integer variable from a C#.Net Win Form to another C#.Net Win Form within the same project
First off. It is really really bad practice to declare member variables in a class as public (You also mention C++ and it is bad practice there too - Remember that just because a programming language allows you to do something doesn't mean that it is a good idea to do it.). You are right to want to use the get/set property accessors.
kd7gim wrote:
am thinking that maybe I should pass by reference instead of pass by value
You don't explain why you'd want to do that, so I am going to assume that since you only mention passing from one class to another (but you didn't mention passing it back again) that this is grasping at straws. Passing by reference is somewhat similar to passing a pointer in C++.
kd7gim wrote:
There is so much difference between SDK Compiler code, and Visual Studio Win Form code
Is there?
You haven't mentioned anything about your design so I really don't know how these two classes are interacting (or supposed to interact). There are countless ways to pass an integer value from one class to another. For example, a constructor could be create that take the integer value, a setter property in the second class could accept the integer from a method in the first class, a getter in the first class could reveal the value to a method in the second class, a method call to the second class could accept the integer, the second class could have an event handler where the integer is part of the event arguments, etc. etc. etc.
Anyway, I hope you can post back with more detail as it will help greatly with finding a solution.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
I have a C# application I have already written, and I am adding a MDI Graph page. The graph page is already written, and the parent document is a C# Data Base Management System. So I do a search in the DBMS. load data onto a stack, then pass these values to my Graph page, and draw the graph.
It looks pretty slick, all I have to do is pass the data to the Graph page.
|
|
|
|
|
kd7gim wrote:
I have a C# application I have already written, and I am adding a MDI Graph page.
Okay, sounds reasonable.
kd7gim wrote:
The graph page is already written, and the parent document is a C# Data Base Management System
Document? Did you ever program with MFC? WinForms applications don't have anything equivalent to the MFC's Document/View implementation of the MVC (Model/View/Controller) pattern, so you generally have to roll your own.
kd7gim wrote:
load data onto a stack
A stack? Do you mean a System.Collections.Stack[^] object? If so, why?
If not, then remember that all object except for intrisnsic objects and other value types (like Point, DateTime, etc.) are created on the heap in C#.
In your original post, you asked about passing an integer between two classes (specifically Form classes). Now that I know one is an MDI Parent Form and one is an MDI Child Form I can show you at least one possible example:
In the parent MDI form you will have some method that needs to send data to the child MDI form. So some piece of code like:
MyGraphFormInstance.MyDataValue = someDataValue;
In the child MDI form you will have a corresponding piece of code ready to receive this data, something like:
public int MyData
{
get
{
}
set
{
}
}
Or you may like to implement the above getter as a method and send multiple items of data at the same time, or have some return value sent back to indicate some change in state. It depends on what you need to do.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
I have worked with the get{}; set{}; passing from private to public on both ends, and using a sender and receiver. I have also worked with global structs. I believe there is a major hole in .Net Version 7. This is also what Mueller, ".Net Framework Solutions, In Search of the Lost Win32 API" claims.
It upsets me to think that I should pay a minimum of $549.00 for an upgrade so that I can get what should have been in Ver 7 in the first place. I think passing public variables has been addressed in Net 2003, as they now advertise their "Global Assembly Cache." Going that far, they are sure to have covered the more basic ground.
I am going to play with pointers, after that I am going to create another external file prototype. I will give it a .ini, or .ocx suffix, and then I will open, and read that file form my second Win Form. This provides me with the job security that a programmer so richly deserves.
|
|
|
|
|
I am at a loss as to understand what you are trying to achieve and even what you are saying.
kd7gim wrote:
I think passing public variables has been addressed in Net 2003
What do you mean by this? It certainly isn't what I think you mean because the context of the rest of your email doesn't support my interpretation of your words.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
Can one modify the icon shown in the setup wizard easily? is there a property somewhere for this that I'm missing?
--Tony Archer
"I can build it good, fast and cheap. Pick any two."
|
|
|
|