|
Well, one solution would be to read the articles . I did not.
Judging from what I am seeing in your code, I suggest that you check to see if you already have a thread going for that file, and terminate.
Basically, this is a design issue. The world is such that you can't count on a single create event. So, if you don't want multiple threads going, you're going to need to do your own checking.
|
|
|
|
|
I have two .csv files .. one is a filter content and the other is national data. The national data file crashes when Excel tries to open it BUT if my PM "uses Access" he can open all of the data.
I used a StreamReader and did an inline ReadLine() but that got the same result as Excel -- out of memory error. Then I read that if you get an out of memory failure using ReadLine that using the more robust Read() will resolve the issue.
I changed my code to use an inline method called GetLine() so that I didn't change my code too drasitcally and ran a test. It still runs out of memory. (code is below) Anyone have any ideas on how I can get past the I/O failure?
private string GetLine(StreamReader reader)
{
if (reader.Peek() < 0) return null;
List<char> buffer = new List<char>(limit);
while (reader.Peek() >= 0)
{
buffer.Add((char)reader.Read());
if (reader.Peek() < 0) return Debuff(buffer);
if (buffer.Count > 3 &&
(buffer[buffer.Count - 1].Equals('\r') && buffer[buffer.Count - 2].Equals('\n')) ||
(buffer[buffer.Count - 1].Equals('\n') && buffer[buffer.Count - 2].Equals('\r')))
return Debuff(buffer);
}
return Debuff(buffer);
}
|
|
|
|
|
First question how big does buffer get?
|
|
|
|
|
Well, believe it or not your question solved my problem. I added a try{}catch{} and found that the buffer exceeded 256MEG in size. Much larger than any record in the file could possibly be. So I traced the characters and found that it only contained a \n by itself at the end of each line.
Found many other inconsistancies in the file (like quoted numbers) but the application is now processing the file without exceeding memory!
Thanks for the help.
Michael
|
|
|
|
|
The advice that you received that the Read method is more robust is due to the following: The readline method goes until it finds a newline character. If you have a 2,000 GB file with no newline characters, then ReadLine attempts to read it ALL into memory (which is clearly going to throw an out of mem exception). The code you provided above is using Read, this is true. But you are still getting the same exception because you basically just reimplemented the same functionality, and are still trying to load a 2000 GB file into memory. The reason why Read is suposedly "safer" is because typically, you only need a portion of the file at any given time. Read into memory only that which you need, or at minimum put a limit to the file size you can handle. Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
The following code is generating files perfectly, But when i change the date on my laptop to get files with different modified times. It just overrides all the files with the recent date.
private void GenerateTestFiles_Click(object sender, EventArgs e)
{
StreamWriter outStream = null;
string message = null;
for (int i = 0; i < (100); i++)
{
string filename = "output";
filename += i.ToString();
if (i % 3 == 0)
{//multiple of three
filename += ".txt";
}
else if (i % 5 == 0)
{//multiple of 5
filename += ".log";
}
else if (i % 7 == 0)
{// multiple of 7
filename += ".exe";
}
else if (i % 9 == 0)
{// miltiple of 9
filename += ".dat";
}
else if (i % 11 == 0)
{// multiple of 11
filename += ".jpq";
}
else
{
filename += ".bmp";
}
FolderWatcher fw = new FolderWatcher();
filename = fw.FolderPath + "C:\\CsharpTempFolder\\" + filename;
try
{
outStream = new StreamWriter(filename);
outStream.WriteLine("Hello World");
outStream.Close();
}
catch (Exception Ex)
{
message = "Unable to create " + filename + "\r\n";
message += String.Format("Reason: {0}", Ex.Message);
MessageBox.Show(message);
}
}
}
1. Can i generate files with random numbers. Like, in the loop i takes random values using System.Random class. Or, add datetime object. what is the most simpliest way of doing it.
|
|
|
|
|
Wouldn't it be easier to just use Path.GetRandomFileName[^]?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
pmarfleet wrote: Wouldn't it be easier to just use Path.GetRandomFileName[^]?
What the?!?... i can't beleive thats actually a built-in method. Why would that be there?
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
SK Genius wrote: Why would that be there?
Because .NET rocks.
Seriously, the purpose of this method is to provide the means of generating a random directory/file name that is cryptographically secure, i.e. that could not be guessed at by a malicious script.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
wow..........thats crazy..i will try it out tomo
|
|
|
|
|
pmarfleet wrote: the purpose of this method is to provide the means of generating a random directory/file name that is cryptographically secure
It has nothing to do with cryptographically secure anything. All it does is genereate a filename that is guaranteed to be unique within the folder where it's created. This function can only generate 65535 unique temp filenames before it throws up an exception. The solution is to delete the existing temp files in the folder and try again.
|
|
|
|
|
My choice of words was wrong. I should have said cryptographically strong, i.e. unpredicatable (quoting from the MSDN documentation).
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
pmarfleet wrote: quoting from the MSDN documentation
There's nothing crypto about the GetTempFileName or GetTempPath methods or their results. At a mere 65535 possible filenames, "strong" isn't the word I'd chose.
Perhaps you were looking at the GetRandomFileName[^] method?
|
|
|
|
|
Dave Kreskowiak wrote: Perhaps you were looking at the GetRandomFileName[^] method?
I was referring to the GetRandomFileName method. See my original post[^]. At no point did I refer to GetTempFileName or GetTempPath .
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I have spent many hours googling this today, and I'm no closer to finding an answer 9or finding an answer I can understand!)
I have a very simple Web Service conforming to WsiProfiles.BasicProfile1_1. It runs on IIS 7, on which I have enabled dynamic content compression, and I'd like to be able to compress this content when it's to...
... my very simple WCF Service client. I created this by using the wizard and pointing it at my web service. The problem I have is that I (think) need my client to send the "yes, I understand compression" header to IIS, and then to understand the compressed response it gets. However, google as I might I can't fathom how to do this. There was some talk of needing to use a compression channel (and I found this on CodePlex: http://www.codeplex.com/wcfextensions[^]), but I'm not sure this is what I need. But in my app.config, there doesn't seem to be any option to enable compression awareness.
Surely this is a common enough thing to want to do that it's included in the box?
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Hi Friends,
I have created a C# .net windows project. There is a form which has used a DataGridViewLinkColumn cell in datagridview. How can i change DataGridViewLinkColumn text when after binding value to datagridview?
Thanks in advance,
Rameshkumar Thirumalaisamy
|
|
|
|
|
Is there a simple way to get the number of files in a current directory?
|
|
|
|
|
|
Directory.GetFiles(".").Length
|
|
|
|
|
Thank you Gentlemen. I knew it was simple but couldn't find it readily.
|
|
|
|
|
hi,
i have a list view control with columns :
Book Name, Author, date released, cpies sold
the book name represents the name of the object
i'd like to do sorting by each header ny cliking the header
the problem is that i only have Auto sort to the object name
i.e the book name header, but i like also to do to all the aother header
haw can i do it?
or should i use the datagridview insted??
THNKS
Have Fun
Never forget it
|
|
|
|
|
Hi!
You should use the ListViewItemSorter property of the ListView . The documentation on MSDN contains examples for this.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi all,
I have devoloped an appliction which will set my internet settings.
I have listbox,textbox etc.
The basic idea is that in a button click event the settings that i see in my text boxes should get applied to my computer.
it takes the values from a xml file.
now i am at a point where it displays all the values.
Now i want it get applied on my computer so that on a button clck i can switch between two of my service providers.
So i need help in knowing "how can i make the settings that is in my text box to get applied to my computer so that on a button click i can switch the internet connections".
May be if i show you my code it will be better
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Net;
using System.Diagnostics;
using System.Threading;
namespace InternetApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
XmlTextReader xmltxtRdr = new XmlTextReader("XMLFile1.xml");
private void btnSwitch_Click(object sender, EventArgs e)
{
Process netshobj = new Process();
netshobj.StartInfo.FileName = "netsh";
netshobj.StartInfo.CreateNoWindow = true;
netshobj.ErrorDataReceived += new DataReceivedEventHandler(netshobj_ErrorDataReceived);
//netshobj.StartInfo.Arguments = "netsh";
// Here i tried these to check whether it will work or not and the result is that it shows a netsh window and tahts it.My settings are nit changing//
netshobj.StartInfo.Arguments = "interface ip set dns 'Local Area Connection' static 192.168.1.255 primary";
try
{
netshobj.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void netshobj_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
MessageBox.Show("The method or operation is not implemented.");
}
private void lstProvider_SelectedIndexChanged(object sender, EventArgs e)
{
GetConnctionSettings( lstProvider.Text);
}
private void GetConnctionSettings(string provider)
{
XmlTextReader xmlTxtRdr = new XmlTextReader("XMLFile1.xml");
while (xmlTxtRdr.Read())
{
if (xmlTxtRdr.Name.ToString() == "connectionName")
{
if (xmlTxtRdr.ReadString().Equals(provider))
{
xmlTxtRdr.ReadToNextSibling("SubNetMask");
txtSubnet1.Text = xmlTxtRdr.ReadString();
xmlTxtRdr.ReadToNextSibling("DefaultGateway");
txtDefaultgateway.Text = xmlTxtRdr.ReadString();
xmlTxtRdr.ReadToNextSibling("DNS1");
txtPrimarydns.Text = xmlTxtRdr.ReadString();
xmlTxtRdr.ReadToNextSibling("DNS2");
txtSecondarydns1.Text = xmlTxtRdr.ReadString();
xmlTxtRdr.ReadToNextSibling("DNS3");
txtSecondarydns2.Text = xmlTxtRdr.ReadString();
GetIP();
}
}
}
}
public void GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
//MessageBox.Show(strHostName);
IPAddress[] addr = ipEntry.AddressList;
//MessageBox.Show(addr[0].ToString());
txtSubnet2.Text = (addr[0].ToString());
//return addr[addr.Length-1].ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
//Load connection names to list box.
getConnectionNamestoListBox();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void getConnectionNamestoListBox()
{
while (xmltxtRdr.Read())
{
if (xmltxtRdr.Name.ToString() == "connectionName")
{
lstProvider.Items.Add(xmltxtRdr.ReadString());
}
}
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void btnCancel_Click(object sender, EventArgs e)
{
MessageBox.Show("You are about to quit Internet Switcher ");
this.Close();
}
}
}
Thanking You
j
|
|
|
|
|
Hello,
I have two webparts. They are connected - one is the provider, one the consumer. The consumer maintains a gridview. Whenever I data arrives from the provider, I call the CreateChildControls in my ConnectionConsumer method. Thus my gridview is rebuilt. But - the CreateChildControls has already been called once, at this point. I'm thinking I should go about this in a different manner. Any ideas? Thank you very much in advance.
Morten
|
|
|
|
|
Hi All,
I have created a delegate and called method in one process. And I am trying to fire event corresponding to this delegate. Programm was running without errors and exceptions. But event handing method was not firing.
could you please suggest me what I made wrong.
Thanks for great support and knowledge sharing.
--------------------------------------------------------------------------------
I have created a form with one delegate:
namespace DelegateDefenitionContainedApplication
{
public delegate void HiSrinivas(object sender, EventArgs e);
public partial class Form1 : Form
{
public static void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("You are succeeded");
}
}
}
And I have created one console application using following way:
namespace EventCaller
{
class myEventClass
{
public static event DelegateDefenitionContainedApplication.HiSrinivas ClickMe;
public void abc()
{
ClickMe += new DelegateDefenitionContainedApplication.HiSrinivas(DelegateDefenitionContainedApplication.Form1.button1_Click);
}
}
class Program
{
static void Main(string[] args)
{
try
{
myEventClass mySrinivas = new myEventClass();
mySrinivas.abc();
}
}
}
}
|
|
|
|