|
1. I know i had endless loop. I wanted to fill my memory and using Virtual Memory as a test. But didnt happend. It threw me System.OutOfMemoryException. And even your sample has infinitive loop. processInfo will never be null, because you intalize it.
2. Read rule #8
|
|
|
|
|
You can also get that exception if you have Int32.Max (2,147,483,648) number of items in the list and then try to add another one.
|
|
|
|
|
Thanks for the info. So it was List limitation, not memory. I Hope i wont have to utilize hdd for temp storage.
|
|
|
|
|
You need to allow programs to access more than 2GB of memory on an OS level. Please read your OS manual to set that.
|
|
|
|
|
When new can't allocate the memory, it returns null .
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hey
All I am trying to do is print a file from c# can't seem to get anything to work. Some of the requirements are:
1) need to have the print dialog box appear
2) print proper file
Thanks,
ZachBob
~Any help is good help
|
|
|
|
|
What sort of file, just text ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
|
Hi,
have a look at the Process and ProcessStartInfo classes, and use Verb="Print"; that way
your default PDF reader will do the actual printing. AFAIK that is the easiest way.
There is one disadvantage: the PDF reader will remain open (unless you add more code to close it,
which is a bit tricky).
|
|
|
|
|
Thanks Luc,
Tried using the Process and ProcessStartInfo classes, but I am getting an Acrobat.exe - Application Error.
Here is my code:
Process printPDF = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.Verb = "Print";
psi.FileName = Server.MapPath(tmpPdf);
psi.CreateNoWindow = true;
printPDF.StartInfo = psi;
printPDF.Start();
What am I doing wrong?
|
|
|
|
|
Hi,
if this is a Windows app, just do psi.FileName=tmpPdf;
I don't know what Server.MapPath is.
is this an ASP.NET application? if so, where is the PDF file, is it on the server?
anyway, double-clicking the PDF file should open your PDF reader, try that and check it
prints OK from there. If not, your file is bad.
|
|
|
|
|
It is actually a web application.
Server.Map - Returns the physical file path that corresponds to the specified virtual path on the Web server.
The pdf opens just fine outside of the web app.
here is some more code to help out:
I start by combining some PDFs into one pdf, then I show it in a pane, then I want the print dialog box to show right after it loads in the pane...
tmpPdf = "/temp/" + Session.SessionID + ".pdf";
PrepareCombinedFile();
FileStream fs = new FileStream(Server.MapPath(tmpPdf), FileMode.Open);
byte[] pdf = new byte[fs.Length];
fs.Read(pdf, 0, Convert.ToInt32(fs.Length));
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Length",pdf.Length.ToString());
Response.BinaryWrite( pdf );
Response.Flush();
Response.Close();
fs.Close();
try
{
Process printPDF = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.Verb = "Print";
psi.FileName = Server.MapPath(tmpPdf);
psi.CreateNoWindow = true;
printPDF.StartInfo = psi;
printPDF.Start();
}
catch(Exception ex)
{
throw new Exception(ex.Message, ex.InnerException);
}
|
|
|
|
|
Hi,
this code is running on the server, it attempts to print on the server.
I doubt that is what you want.
Your browser should allow you to print a loaded page (or PDF document) on the client side,
either an interactive browser (IE7, FF, ...) or a programmable one (WebBrowser) or a
program using WebRequest and GetResponse.
|
|
|
|
|
correct - I want the print dialog box to appear on the client side. And yes, I am able to print from the loaded page, but the client would like the print dialog box to appear immediately after the pdf loads. Why, I don't know .
|
|
|
|
|
Hi,
I don't know how to do that in a standard browser.
In a WebBrowser Control, I would use the DocumentCompleted event, then write standard
printing code.
|
|
|
|
|
Hi,
I now have seen some pages that do just that. It is based on the onload event and some
JavaScript, using window.print()
As an example, take this[^], click the little printer icon at the bottom, see another page load and have a look
at its source code.
Hope this helps.
|
|
|
|
|
I'm developing a USB device that is communicating with a C# program through a serial port interface.
I identify my device using SetupDiGetDeviceRegistryProperty, reading the HardwareId and searching for my VID and PID in the string that is returned. (Don't know if this is the fastest/best way, but it works...)
For the communication I would like to use a SerialPort component so I need to get the COM port used by my device but I can't find that information using SetupDiGetDeviceRegistryProperty.
Using the Device manager the information is available under Properties/Port Settings/Advanced/Com port number and in the registry it can be found at HKLM\Hardware\DeviceMap\SerialComm but how do I access that information from my C# code?
Thanks!
|
|
|
|
|
Hello Forum
I was looking for a way to dynacmicly open a form and realize that the best way will be to use reflection.
It is the first time i am using reflection and think that i am alomost there but it still doesnt work.
i am getting a message "Object does not match target type."
Bellow is the code.
Please help
Type theType = Type.GetType("WindowsFormsApplication1.Form2");
MethodInfo[] method = (from met in theType.GetMethods()
where met.Name == "Show"
select met).ToArray();
Activator.CreateInstance(theType);
method[0].Invoke(theType, null);
|
|
|
|
|
Why do you need to use reflection ? You know the type, right ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Correct,
I am looking for a way to create a method that will open any form,
the form name will be suppled in a string parameter,
I thoght this is the best way to achive this, can you think of any other way?
Thanks for your attentetion
|
|
|
|
|
belzer wrote: can you think of any other way?
The good news is no one has to think of another way because Creational Patterns[^] have been known and documented for years.
led mike
|
|
|
|
|
If you only know the name as a string, did you get it from reflection ( that is, are you on a bizarre quest to write code that will open any form from any dll ), or is it from a known list ? As someone else said, in the latter case, a Factory pattern is what you want.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
It is from a know list.
To be more specific.
I am building a menu where the menu list is populated form a table that contains the Menu Caption and the Module that should be called on click.
There the long way is where you analyze the menu clicked and then call the corresponding module Like: if menu clicked = A call module x and if menu clicked = B call module y.
But my program may contains about 100 modules and I think the factory pattern will be lots of code lines.
Thanks again
|
|
|
|
|
Writing a project for a client using .NET 3.5 in C#. I need to import data from an XLS spreadsheet into a SQL data table. Problem is, one of the columns in the date table contains an "optional" date field. In the sample file provided by the client, no data exists in that optional field until row 27. The result is that NO ROW contains the optional field in the final SQL table.
I've been using an ODBC connection (MS Jet 4.0) to read the XLS. I tried adding MAXSCANROWS=0, which according to what I've read should allow the first 16384 rows to be used in determining column types. However, this seemed to have no effect.
I read another article that suggested the work-around is registry editing. That's not too practical, especially for deploying this project to the client's server.
Does anyone know another way to get the data to import correctly?
Thanks.
|
|
|
|
|
I've had nightmares trying exactly this kind of thing in Excel. That and the fact that if someone has the file open ODBC doesn't revert to a readonly mode as would happen if 2 people opened an xls file in the conventional manner.
As i remember if the first populated field within a column contains an integer you then get problems if subsequent fields contain text etc.
I think i ended up using the PIA approach and reading the data out cell by cell. It's slightly more laborious but gives a much finer level of control over what is happening
Russ
|
|
|
|