|
I think you can solve this issue by using .NET Reflection. Take a look at this article (TraceListeners and Reflection)[^] - it contains enough to get you started.
In the example, the author of the article shows how to log information such as the calling function on the stack and the argument list of that function. He also explains how you retrieve information about the call stack.
Hope that helps!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Tank's for the answer!
I try to use the refered article, to work out the correct solution.
-- modified at 3:37 Thursday 20th July, 2006
I checked the article, its good, but isn't do what I want. This type of logging stil need to be modyfy the target program.
I need solution to log a program/process without modifying it's code...
|
|
|
|
|
My progress bar in the status bar doesn't want to run.
The application I created is a SQL tool for an oracle db I work on. Basically, I just type my SQL code in a RichTextbox and then the data comes back in my datagrid. That works fine.
I thought it would be cool if I could add a progress bar and set it to marquee while I was waiting for my data to come back.
I'm pretty sure I need to multi-thread this beasty but when I do I get the following message: "Cross-thread operation not valid: Control 'rtbSQL' accessed from a thread other than the thread it was created on."
Here's what I passed to the new thread (which is created when I click the run button):
btnRunSQLClick(bla bla...)
{
Thread t1 = new Thread(new ThreadStart(GetData));
t1.Start();
}
the GetData() code:
public void GetData()
{
try
{
da=new OdbcDataAdapter(this.rtbSQL.Text, this.cnn);
cb=new OdbcCommandBuilder(da);
dt=new DataTable();
da.Fill(dt);
}
catch(OdbcException ex)
{
MessageBox.Show(ex.Message);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
this.dataGrid1.DataSource = dt;
}
Any ideas? I'm definitely a novice at threading!!
|
|
|
|
|
If you are using 2.0 you could use BackgroundWorker and subscribe to the OnProgressChanged event to update your progressbar.
Otherwise you need to use an event to update your progressbar in the UI thread or use invoke on the progressbar to update it.
Take a look on this site for some good examples of multi-threading
|
|
|
|
|
The problem is the following line: da=new OdbcDataAdapter(this.rtbSQL.Text, this.cnn); . As the error message says accessing a control a thread other than the thread it was created on isn't allowed.
You should retrieve the value of the this.rtbSQL.Text property before starting the worker thread and then pass it to the method. Therefor you could either use this overload of the Thread.Start method[^] or follow techniques presented in this MSDN article[^].
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
I want to read a very large files such az log files in IIS line by line with an especial format for each line (by c#),Which way or function do you recommand?
-- modified at 11:37 Wednesday 19th July, 2006
|
|
|
|
|
StreamReader reader = new StreamReader("MyFile");<br />
string strLine;<br />
<br />
while( (strLine = reader.ReadLine() ) != null )<br />
{<br />
}
|
|
|
|
|
tail ?
(download cygwin)
or perhaps
// warning, pseudo-code, if it doesn't compile => fix the code yourself
static void Main(string[] args)
{
string line;
using(StreamReader sr = new StreamReader(args[0]))
while((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
Console.ReadLine();
}
}
|
|
|
|
|
Hello
first of all thanks for answer,So Fast!
Look
the problem is that these are huge file,Maybe 1G...
The solution that you recommanded ,have problem of speed,I want a solution that read file faster.
Thanks in advance
|
|
|
|
|
It is two parts, one you have to use a stream with a file so big because you do not have the memory to do otherwise. Secondly, if the file is not indexed your SOL. If it is indexed you can use any traversal algorithm to get the data you need. ( I did this technique with the national do not call list and it works fairly fast)
Also, you may consider c++ if you just need speed.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: Also, you may consider c++ if you just need speed.
I'm not sure how much that would help though. The filesystem would still be the bottleneck in performance.
|
|
|
|
|
You can use memory mapping in C++ which will reduce the bottle neck for speed.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
what is it you want to do?
the question was: "I want to read a very large files"
I told you how to read without memory problem.
Now it can't read faster than you!
Had the question be: "I am looking for a particular pattern" I might have added an automated search function.....
But if you want to read it all, you've got to do it man!
|
|
|
|
|
I have a loop to send aysn message to different clients as below.
but even if all the clients are online and the configuration of all the clients are the same, I can only received a part of responses from clients.
Would you pls give me some suggestion about this problem?Thank you
code below------------------------------------------------------------------
foreach (IPEndPoint endPoint in this.endPoints)
{
try{
udpClient = new UdpClient();
udpClient.Connect(endPoint);
udpClient.Send(buf, length);
udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), new UdpState(udpClient, endPoint));
}
catch (Exception ex){
}
----------------------------------------------------------------------------
Sincerely,
WeiYu Wang
|
|
|
|
|
Hi,
i am using a windows DateTimepicker. When i click the up/down arrow button when the control is not having focus, it increments the value first and then sets the focus to control. If i want to do some validation before value changes, what event i should be handling? Basicall what i want is if the user click the up down arrow button, i want the mins field to increment instead of hours field. Format for my datetime picker is hh:mm:ss. By default the focus is on the hour field, i want the mins field to have focus.
any idea?
venkat
|
|
|
|
|
Have you tried the ValueChanged event
|
|
|
|
|
i cannot do on value change because if the user himself changes the focus to hour field and then increments, value change should increment the hour. I just want to set the default field to increment as mins. ValueChanged event happens after the value has been changed, so i don't want to revert back. If the focus is not in the control, user clicks the updown button, it should change the min field instead of hour but if the control has focus and user has selected hour field it should change hour. I just want to change the default from hour to mins.
|
|
|
|
|
I'm working on some in-house software to calibrate a product. I've written code with MS Visual Studio Express C# on my PC, running XP and Office 2000. It uses "System.Runtime.InteropServices" and Excel and Office bits to communicate with Excel. It works fine.
When I come to try it out on the PC that will be used, there's an error about Interop being the wrong version when installing. That PC is also running XP, but has Office XP. I downloaded some runtime Interop for Orfice 2003, and XP, but they didn't make any difference. Do I need the targe systems version of Office to make an application that will install and run?
|
|
|
|
|
Hello, I have setup a timer to simulate cursor blinking. My program has multiple threads. the thing is that my timer went off but it never calls the function delegate to the Tick events.
Do you what is reason? why the tick event nevers calls the function to do my blinking?
private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Tick += new EventHandler(BlinkMode);
timer.Interval = 150;
timer.Enabled = true;
//=============================================================
// timer tick handler
//=============================================================
private void BlinkMode(Object obj, EventArgs ea)
{
if (!BlinkCursor)
{
if (curX < 19) // Don't show the cursor if it's at the end of the line
{
DrawChar('_', curX, curY); // Draw an underscore char at the current coordinate
BlinkCursor = true;
}
}
else
{
DrawChar(HiddenChar, curX, curY);
BlinkCursor = false;
}
}
Donkaiser
|
|
|
|
|
You must start the timer.
timer.Start();
|
|
|
|
|
timer.Enable starts the timer
|
|
|
|
|
Hello,
I think when you are multi threading, you have to use System.Timers.Timer Class.
With Timer.Elabsed Event.
All the best,
Martin
|
|
|
|
|
Try to put your code in method BlinkMode in try catch.
If you get an exception, then you have a problem with the other thread.
Use this to avoid exception :
private void Blinking()
{
}
private void BlinkMode(Object obj, EventArgs ea)
{
MethodInvoker mi = new MethodInvoker(Blinking);
Invoke(mi);
}
|
|
|
|
|
I just want to be more specific about what im doing. Im developping with CF 2.0 VS 2005 and C#.
I have a class library which simulate a VT100 like terminal, and i added it as reference to my project. From my main project i call a method from that added class library. In this method, I process all the data that need to be printed on the terminal screen and then i set the timer like the code above which will trigger the BlinkMode method. while debugging, I can see that my timer went off but nothing from the BlinkMode() works.
Donkaiser
|
|
|
|
|
well after the timer got fired, BlinkMode() never been called. that why it's weird. I see what you waant me to do but if the BlinkMode() never get called so do the Blinkinh().
Donkaiser
|
|
|
|