|
Malcolm Smart wrote: - is it not good practice then to call GC.Collect?
It's generally not, but for testing purposes doing it will let you see if the GC simply hasn't gotten around to releasing the memory, or if there's an actual leak.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
Well, Microsoft says that Garbage collection does take up resources time etc. So in general the discourage its use mainly for performance reasons. If they really didn't want us to use it they wouldn't have exposed it.
My experience with it is, it can seem that you might have a memory link, but for some reason garbage collection has just not decided to run. Anyway, if you run it manually you will know if you have a memory link or not.
Ben
|
|
|
|
|
Garbage collecting made no difference. I'm going to try and run the pings synchronously now - will take an age as we have so many machines in the farm, but it will eliminate the asynch aspect of the call.
Watch this space....
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
I think if you had a generic list out side of the method you could save and then dispose of the ping objects. I think because you define the ping object in the method it is defined as a local variable. So then when you try to free it in the callback it doesn't work. Just my guess looking at the code.
Ben
|
|
|
|
|
You are not disposing of the Ping object if it throws an exception
|
|
|
|
|
I am, but not in the version of the code posted - honest!!!! I cut that down to its bare bones....but....the farm I am pingnig has about 1700 machines, and only 2 causeP Ping to through. The apparent memory leak is proportional to the number of machines pinged.
I'll post back my 'GC.Collect' resulst from the above post shortly.
Thanks.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
O ok
|
|
|
|
|
It seems the ASync call of Ping doesn't like havnig hundreds of them kicking about. I changed the code to call the ping synchronously, but placed the call in a worker thread, effectively giving me an asynchronous call. Works a treat..
class pinger
{
public static int PingsOutstanding = 0;
public string IP;
public void PingIt()
{
try
{
System.Threading.Interlocked.Increment(ref PingsOutstanding);
Ping ping = new Ping();
ping.Send(IP, 100);
}
catch (Exception e)
{
}
finally
{
System.Threading.Interlocked.Decrement(ref PingsOutstanding);
}
}
}
foreach (string ipAddress in _check.GroupData)
{
pinger p = new pinger();
p.IP = str;
new System.Threading.Thread(new System.Threading.ThreadStart(p.PingIt)).Start();
}
while (pinger.PingsOutstanding > 0)
{
System.Threading.Thread.Sleep(500);
}
This works, perfmon doesn't even blink about the memory being used, and it seems just as quick, if not quicker...happy for destructive criticism on this method!
Thanks all for the help.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Malcolm Smart wrote: It seems the ASync call of Ping doesn't like havnig hundreds of them kicking about.
No it doesn't. You'd have to convert the code to limit the number of threads you have running pings. Perhaps queuing up the list of IP's to hit and having 10-20 or so ping threads feeding off that queue...
|
|
|
|
|
Hi, I'm a Java Developer wishing to Migrate to C#. Please provide me some ebook meant for Java Developers whiching to migrate to C#.
Thanks...
P.S: I'm new around here so please move my post to the appropriate section if it does not belong here.
|
|
|
|
|
Java and C# are very similar. I don't know of any ebooks, but I know there are a couple of books available for purchase. Overall, I'd say if you found some articles online ( just google it ), and then you started to play with C#, you wouldn't have much in the way of problems.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Like Christian said, Java and C# are quite similar. I learned Java at the university and C# on my own (and with help of Code Project articles ). There isn't a real sharp learning curve. Only difference is the most of the classes you find in .NET versus Java. There are many that are similar. Have fun learning C# and you did pick the right forum for asking C# questions.
There are many very knowledgeable members on this site, so feel free to drop a question anytime
Paul
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
http://msdn2.microsoft.com/en-us/library/ms228358(VS.80).aspx[^]
This should get you started!
P.S. -- My first experience with both C# and Java was to port a project from Java to C#! I found most of my job was to run find/replace to replace methods like String.length to String.Length etc... The biggest bug that I created while doing this was that String.substring in Java has the same parameters as String.Substring in C#, but they do different things (index to index vs index to length).
Good luck!
|
|
|
|
|
Thanks Phil. Thats Quite helpfull...
|
|
|
|
|
Look at the Java Language Conversion Assistant (google for JLCA 3)
|
|
|
|
|
Hi frinds,
First of all thanks, I got the code to Convert CSV file to XLS file using Excel Application object.
My code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using Microsoft.Office.Interop.Excel;
namespace File_Conversion
{
class Program
{
static void Main(string[] args)
{
ApplicationClass app = new ApplicationClass();
Workbook doc = app.Workbooks._Open(
@"C:\GCProject\Input Example.csv",
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
false,
Missing.Value,
Missing.Value,
false);
Console.WriteLine("Reading CSV File........");
doc.SaveAs(
@"C:\GCProject\Output.xls",
XlFileFormat.xlWorkbookNormal,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
XlSaveAsAccessMode.xlExclusive,
Missing.Value,
false,
Missing.Value,
Missing.Value,
Missing.Value);
doc.Saved = true;
Console.WriteLine("Converted CSV to XLS file");
app.Quit();
Console.ReadLine();
}
}
}
But Now, I have to get specified format, Like follows.
My CSV file Contains Data like.
-----------------------------------
Ex: DriverID | CustomerID | Ship to ID | Load # | BOL Date/TimeStamp |PrdNam
520 | 2355 - | 1 | 61953 | ############ | 1 Eth 87
My XLS file Contains Data Like.
-----------------------------------------------------------------------------
Ex: Field | Definition | Length | Starting Column | Ending Column |
-----------------------------------------------------------------------------
delimiter"
-----------------------------------------------------------------------------
TransType|Some Definition |1 | 1 | 1
|
-----------------------------------------------------------------------------
delimiter ","
-----------------------------------------------------------------------------
Termin ID | Some Difinition| 3 | 3 | 5
|
-----------------------------------------------------------------------------
delimiter ","
-----------------------------------------------------------------------------
Term SPLC | Some Difi | 7 | 6 | 12
|
-----------------------------------------------------------------------------
I got the code converting CSV file to XLS file. But What I need is Converted
XLS file should look like above format in Converted Excel sheet.
Any body have Idea !!!!
Hope I explained well.!
Thanks in advance.
Regards,
Liyakhat.
|
|
|
|
|
here are 2 ideas:
1) do the open and save methods allow you to specify the format of the input/output? In the save parameter list there's XlFileFormat.xlWorkbookNormal - is there another format in that enumeration that better represents what you want? Try looking here[^] for information about those methods
2) parse the .csv and print your .xls files manually. This will obviously require more work but will ultimately give you much more flexibility with your format conversions. Here[^] is a short example of creating your own Excel file.
|
|
|
|
|
Hi Jammie,
First of all thanks for the reply.
I have tried with the "Open" and "Save" methods of the input/output. :(I have tried with the XlFileFormat.xlWorkbookNormal there is not methods to show in my specified format
I have read those two links which you have sent. But I m not able to find any info related to my task.
Do you have any new Idea ?
Thanks,
Liyakhat
|
|
|
|
|
The most versatile method is going to be to parse the .csv file and create a .xls file manually.
A .csv file is just a text file, so one method of parsing it is to open and read it with a StreamReader[^] and read it line by line. For each line that you read use the split[^] method to separate the values by comma.
Then to create your own .xls file just follow the example in the link that I gave here[^]. All you need to do is get a workbook like they do with this code:
oXL = new Excel.Application();
oXL.Visible = true;
oWB = (Excel._Workbook)(oXL.Workbooks.Add( Missing.Value ));
oSheet = (Excel._Worksheet)oWB.ActiveSheet;
and then write the data into the worksheet however you want. The cells in the .xls file can be accessed just like a two dimensional array, so you can arrange the data however you want. Then save the workbook and you're done!
Oh, and it's Jim, not Jammie
|
|
|
|
|
Hi Jim, not Jammie
I m very happy to tell you that I m able to start my task, You helped me lot in this. I m in half way to finish this task.
Provided links are very usefull to me.
Thanks,
Liyakhat
My Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
namespace ConsoleApplication_Sample
{
class Program
{
static void Main(string[] args)
ReadFromFile("C:\\GCProject\\Input Example_new.csv");
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
Excel.Range oRng;
try
{
//Start Excel and get Application object.
oXL = new Excel.Application();
oXL.Visible = true;
//Get a new workbook.
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel._Worksheet)oWB.ActiveSheet;
//Add table headers going cell by cell.
oSheet.Cells[1, 1] = "Field";
oSheet.Cells[1, 2] = "Description";
oSheet.Cells[1, 3] = "Length";
oSheet.Cells[1, 4] = "Starting Column";
oSheet.Cells[1, 5] = "Ending Column";
//Format A1:D1 as bold, vertical alignment = center.
oSheet.get_Range("A1", "E1").Font.Bold = true;
//oSheet.get_Range("A1", "E1").AutoFormat(12, 1, 12, 10, 5, 0, 10);
oSheet.get_Range("A1", "E1").VerticalAlignment =
Excel.XlVAlign.xlVAlignCenter;
///*Start*/
StreamReader SR;
string S1;
SR = File.OpenText("C:\\GCProject\\Input Example_new.csv");
S1 = SR.ReadLine();
int i = 1;
while (S1 != null)
{
//Console.WriteLine(S);
string S;
S = S1;//SR.ReadLine();
if (S != null)
{
string[] spli = S.Split(new Char[] { ',' });
int j=2;
foreach (string s in spli)
{
if (s.Trim() != "")
{
oSheet.Cells[j, i] = s.ToString();//+ " Liya ";
Console.WriteLine(s);
}
j=j+1;
}
}
i = i + 1;
S1=SR.ReadLine();
}
SR.Close();
// /*End*/
//Fill A2:B6 with an array of values (First and Last Names).
// oSheet.get_Range("A2", "B24").Value2 = saNames;
oRng = oSheet.get_Range("A1", "E1");
oRng.EntireColumn.AutoFit();
oRng = oSheet.get_Range("B2", "B24");
oSheet.get_Range("b2", "b24").ColumnWidth = 75;
oRng.WrapText = true;
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
//AppendToFile();
}
// Reading the File
static void ReadFromFile(string filename)
{
StreamReader SR;
string S;
SR = File.OpenText(filename);
S = SR.ReadLine();
while (S != null)
{
Console.WriteLine(S);
S = SR.ReadLine();
if (S != null)
{
string[] spli = S.Split(new Char[] { ',' });
foreach (string s in spli)
{
}
}
}
SR.Close();
}
}
}
|
|
|
|
|
I am developing a program for pocket pc that uses sqlServer for the database. but when i start the program i have a message error that said that is missing sqlceme.dll.
The error appears when i want to use SqlCeEngine.
I can't add to Resurces and i copied it to Windows and in ProgramFiles to my application directory... but the i get the same error message...
What can i do? Please help me ...
Regards,
Marta Paniti.
--------------------------------
visit: http://pmartike.deviantart.com/
|
|
|
|
|
problem solved
--------------------------------
visit: http://pmartike.deviantart.com/
|
|
|
|
|
hi,
I am working on web application(ASP.NET ,VB.NET) and some reports push on server daily.
GZ (application like winzip) is installed on only server machine not on client machine.
I want to open report in GZ on server from any client machine and print on printer.
Can I do this ?
thanks in advance!!
|
|
|
|
|
No - you can not grab a file from the client, they have to send it to you. You could write a page which loads the report and starts printing, I believe, but at best it would bring up the print dialog, you can't start the printer from javascript.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello everyone,
I am learning how to use C# to implement an OLE DB provider (a simple one which is based on CSV file format). I can not find any samples from MSDN (all samples are C++).
Any reference materials?
thanks in advance,
George
|
|
|
|