|
|
thanks alot.
haven't tried it yet but it may do the job.
also the message posted before that.
thank you both
Ran.Z.
R.Z
|
|
|
|
|
Also see this[^] article which is a framework for retrieving information from the web, which seems like what you appear to be doing.
(Its MFC analog can be found here[^] and several applications of this class can be found here[^].)
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I've got a problem.
How can I pass variables from ReadInput function to ReadOutput function via struct?
Please help.
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace ConsoleApplication9
{
class Program
{
static string m1 = "\nType a string of text then press Enter. " +
"Type '+' anywhere in the text to quit:\n";
static string m2 = "Character '{0}'";
static string m3 = "Character ";
public struct ThreadFuncParameters
{
public char ch;
public int x;
public bool isM1 ;
public bool isM2 ;
public bool isM3 ;
}
static void Main(string[] args)
{
Console.WriteLine(m1);
ThreadFuncParameters pas = new ThreadFuncParameters();
pas.ch = 'a' ;
pas.x = 0;
pas.isM1 = false;
pas.isM2 = false;
pas.isM3 = false;
Thread t1 = new Thread(new ParameterizedThreadStart(Program.ReadInput));
Thread t2 = new Thread(new ParameterizedThreadStart(Program.ReadOutput));
Console.WriteLine("Thread 1 starting...");
t1.Start(pas);
Console.WriteLine("Thread 2 starting...");
t2.Start(pas);
}
public static void ReadInput(object paramALL)
{
ThreadFuncParameters par = (ThreadFuncParameters)paramALL;
char p1 = par.ch;
int p2 = par.x;
bool p3 = par.isM1;
bool p4 = par.isM2;
bool p5 = par.isM3;
do
{
p2 = Console.Read();
try
{
p1 = Convert.ToChar(p2);
if (Char.IsWhiteSpace(p1))
{
p5 = true;
if (p1== 0x0a)
p3= true;
}
else
p4 = true;
}
catch (OverflowException e)
{
Console.WriteLine("{0} Value read = {1}.", e.Message, p2);
p1 = Char.MinValue;
Console.WriteLine(m1);
}
} while (p1!= '+');
ch = p1;
x = p2;
isM1 = p3;
isM2 = p4;
isM3 = p5;
}
public static void ReadOutput(object paramALL)
{
ThreadFuncParameters par = (ThreadFuncParameters)paramALL;
char p1 = par.ch;
int p2 = par.x;
bool p3 = par.isM1;
bool p4 = par.isM2;
bool p5 = par.isM3;
if (p5)
{
Console.WriteLine(m3, p2);
}
if (p3)
{
Console.WriteLine(m1);
}
if (p4)
{
Console.WriteLine(m2, p1, p2);
}
}
}
}
eric
-- modified at 7:54 Wednesday 19th April, 2006
|
|
|
|
|
I'd say your ReadInput thread would end as soon as someone types '+'.
Your ReadOutput thread would end almost as soon as you started it.
To keep your threads alive you need to keep them doing something. So once your thread is initialized, you need to manage it with a while loop:
bool notTerminated = true;
public bool NotTerminated { get; set; }
while ( NotTerminated )
{
Threading.Thread.Sleep(50);
}
Your loader program (containing Main()) would handle the passage of data.
So it would sit in a while loop looking to see if there is something to move out of the first thread. If there is, then it moves it to the second thread and that thread does it's thing.
You could use the get; set; logic for the payload in thread one to change the state for notifying the Main() process.
private bool dataAvailable;
private DataClass mydataload;
public DataClass PayLoad
{
get {
if (dataAvailable)
{
dataAvailable = false;
return mydataload;
} else return null;
set {
dataAvailable=true;
PayLoad = value; }
}
This snippet can be supported in both threads. Your Main() thread checks the state of available data in thread one. Thread two in it's main loop checks it's own state for DataAvailable.
-- modified at 11:26 Wednesday 19th April, 2006
|
|
|
|
|
Thanks so much
I try now
eric
|
|
|
|
|
Hello everyone!
I've finished a windows application and started creating a setup project (VS 2005). Everything works fine: application gets installed and links in startmenu are created. But I don't know how to create a link for uninstallation of my application in the startmenu.? Searched MSDN but without any luck.
Thanks in advance!
www.troschuetz.de
|
|
|
|
|
hi
can anyone help in providing sample code in asp.net1.1 or 2.0 and c# for a discussion forum
|
|
|
|
|
Are you serious? You expect the full code for a discussion forum to be posted here in this message??
There are literally hundreds (if not thousands) of examples of discussion forums, many of which will be open source, if you search the web.
|
|
|
|
|
|
Hi!
I have to write a little program in C#, which I should be able to detect when a new program has been opened.
Does anyone have some sample code or hints where to start in order to detect when a new application has been opened.
Thanks in advance
Werner
|
|
|
|
|
Hi, I'm having a problem with this. I don't know why it could be. I'm trying to access a file in a directory located in the bin/Debug or bin/Release folder of the c#.net 2003 project. I access it like this:
string file = "Folder1\\Folder2\\File.ext";
where the folder is located, as I said, in ProjectFolder\bin\Debug or ProjectFolder\bin\Release
¿When I access this folder, why is the DirectoryNotFoundException thrown?
Why if I put these folders into ProjectFolder\ and accessing with:
string file = "..\\..\\Folder1\\Folder2\\File.ext";
it gives me no problem??
Help please!
Thanx
|
|
|
|
|
Hi!
When you're using relative paths, you always have to be sure what's the current directory of the application.
You should NEVER assume anything regarding on what the current directory is, even showing an OpenFileDialog can change the current directory!
If you need a directory relative to your exe, you should use Application.StartupPath and build the path from there.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
sergestusxx wrote: ¿When I access this folder, why is the DirectoryNotFoundException thrown?
You are getting the exception because folder\folder\folder is not a properly formatted or valid path. On the other hand C:\Program Files\Something is a valid and properly formatted path.
sergestusxx wrote: string file = "..\\..\\Folder1\\Folder2\\File.ext";
As you see from the behaviour, this structure IS a valid path but you obviously do not know why. When you add ..\..\ you are telling File that you are accessing a folder relative to the current directory. In this case the Debug or Release folder of your application.
Follow the other suggestion and append your path with your Application ExecutablePath
|
|
|
|
|
Have you tried...
string file = "\\Folder1\\Folder2\\File.ext";?
I set my projects up to use an external directory structure (out side of the project\\bin\\..).
For example, inside my code I will setup some directory strings as the path to certain folders.
GetCurrentDirectory() + "\\Data\\" is where I would store my database.
GetCurrentDirectory() + "\\Art\\" is where I store my art files.
To set this up, inside the .NET project properties set the Output Pathto ..\\Folder\
Hope this helps.
|
|
|
|
|
Hi!
I tried the Application.StartupPath thing and it works fine. It was maybe caused by an OpenFileDialog I used just before.
I tried adding "\\" first, but the directory wasn't found either.
Thanks for the tip! I was going crazy
|
|
|
|
|
I have to go to develop the webtv application using C#,but i dont know the details about that concept if any body know just answer me
|
|
|
|
|
AFAIK webtv is just a normal web application.
|
|
|
|
|
How would i be able to read data out of the datagrid row by row ? I know how to do it in ASP but a Form's datagrid has different properties. Please help.
|
|
|
|
|
into a function looking like this :
setStatus(id as Integer, Status as System.Nullable(of Short))
The function is automaticly created in the DataSet-designer for "INSERT INTO Status ...."
Regards // Maw
|
|
|
|
|
That's VB. This is a c# forum.
using System.Beer;
|
|
|
|
|
Hi,
i am accessing visio's objects programmatically. I am able to know that in a page how many shape are there and what type of shapes are they. Now I want is to know that class object(s) in a window posses how many properties, Method, className etc. I am able to find out the descricption of process, doc, terminator etc. info. But problem with class object is it contains data in row format. plz do reply soon.
|
|
|
|
|
Hi.
I am experimenting with threading and I made the following simple program:
Thread blue = new Thread(new ThreadStart(bluebegin) );
Thread yellow = new Thread(new ThreadStart(yellowbegin) );
Thread red = new Thread(new ThreadStart(redbegin) );
blue.Start();
yellow.Start();
red.Start();
....
....
public void bluebegin()
{
this.BackColor = Color.Blue;
Thread.Sleep(2000);
yellowbegin();
}
public void yellowbegin()
{
this.BackColor = Color.Yellow;
Thread.Sleep(500);
redbegin();
}
public void redbegin()
{
this.BackColor = Color.Red;
Thread.Sleep(3000);
bluebegin();
}
I don´t know how to stop one or all threads. I have tried adding to one of the methods : blue.Abort(); but then I am told that the namespace blue could not be found. Can someone please help me?
Thanks,
F
|
|
|
|
|
Try creating a click event or a button where you can abort the threads, not in their thread methods.
|
|
|
|
|
public void bluebegin()
{
bool notTerminated=true;
public bool NotTerminated { get; set; }
while ( NotTerminated )
{
this.BackColor = Color.Blue;
thread.Sleep(500);
}
}
That should be enough to have you figure out what to do next.
-- modified at 10:10 Wednesday 19th April, 2006
|
|
|
|