|
Hi Sokka93,
For an excellent discussion of "jagged arrays" compared to "multidimensional" arrays, see : [^]
For performance comparisons of jagged and multidimensional arrays see : [^]
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
|
HI All,
I need to write a routine that read, at same time, 3 files and raise each string on 3 separate event handler.
I think that the correct way to solve this problem is multithread. It's correct?
Can you help me with an example?
Thanks a lot.
Alex
|
|
|
|
|
Can you provide more details?
|
|
|
|
|
I need to read, at same time, 3 files that contain info to horse race. This 3 files contain the info for position istant by istant any horse (time info, x and y for draw point on virtual circuit). The start is equal for ALL, and I need to draw the position of any horse at same time ... and know how arrival first, second and three after passing the virtual "end line" ...
Alex
|
|
|
|
|
How the drawing is initiated?
For example:
I have to update my animation when one of the files is updated on the disk.
Or
I have to update my animation with specific time intervals.
|
|
|
|
|
in 2 mode:
- In real time from event receive from 3 comPort
- in post processing by read all files saved on hard disk (read time field saved internal)
Alex
|
|
|
|
|
Correct me if I am wrong, in both cases the files will contain full history of the race for given horse.
For example:
0 milliseconds 0 meters
2 milliseconds 0.3 meters
8 milliseconds 0.8 meters
12 milliseconds 1.1 meters
…
88354 milliseconds 2000 meters //Finish
|
|
|
|
|
Yes, in theory ... but I don't know what problem can generate a COM PORT EVENT ...
Alex
|
|
|
|
|
Assuming that you have three files with full history of the race for each horse from start to finish and you are requested to create animation that simulates the race while preserving proper timing of the race. That what I would do
1. Load each file into corresponding list. Each list element represents position of the horse and timing of this position. Each list is sorted by time.
2. Merge three arrays into one list. Each list element represent time and position of all three horses at this time. The list is sorted by time.
3. Develop UI control that is capable of painting one race frame based on individual element from array created on step 2. Development of such control might be challenging but in general you have to assure that method called to draw particular frame “HorseRaceArenaControl::DrawRaceFrame (horse1Position, horse2Position, horse3Position ) “ can be called from arbitrary thread. The topics that you have to explore are Control::Invoke, Control::OnPaint, “implementing own-drown control”,
4. To call DrawRaceFrame method for each element in the list created in step 2. The method has to be called with time intervals as recorded in each element. You can use .Net System.Threading.Timer class to assure proper timing.
I realize that this is not detailed instruction but rather general guidelines. Hopefully it can serve as starting point.
|
|
|
|
|
Thanks, this is good solution for post-processing files ... but in real time?
Alex
|
|
|
|
|
Sorry, I failed to understand last statement.
You indicated that you use com3 event to drive “real time” animation. Can you provide more details?
|
|
|
|
|
example ... 3 GPS-GSM that trasfer horse position in real time. I connect a modem receiver to my PC, open a COM PORT for it, ad using, in real time, a sentences that I receive. For any horse.
Alex
|
|
|
|
|
Sounds as horse position is embedded inside com3 message. Am I right?
|
|
|
|
|
Hi:
I just write a simple example for you. I hope it was useful for you.
<br />
class MultiThread<br />
{<br />
Thread td_example = null;<br />
System.Windows.Forms.Control _ctl;<br />
public MultiThread(System.Windows.Forms.Control ctl)<br />
{<br />
td_example = new Thread(new ThreadStart(CalledMethod));<br />
_ctl = ctl;<br />
}<br />
<br />
public void startThread()<br />
{<br />
td_example.Start();<br />
}<br />
<br />
public void suspendThread()<br />
{<br />
td_example.Suspend();<br />
}<br />
<br />
public void abortThread()<br />
{<br />
td_example.Abort();<br />
}<br />
<br />
int i = 0;<br />
private void CalledMethod()<br />
{<br />
while (true)<br />
{<br />
i++;<br />
System.Windows.Forms.MessageBox.Show(i.ToString());<br />
<br />
Thread.Sleep(1000);<br />
}<br />
}<br />
}<br />
good luck!
|
|
|
|
|
the class is 1 for all the 3 istance?
Alex
|
|
|
|
|
You can instantiate the class to a variable. Then use the variable which instantiated to open each files.
I just write a simple example for you. And, this is only a guiding idea. I consider that the more problems solved by oneself the more he/she learned.
There was an old sentence, in our country, said that,"Teaching someone fishing than giving he/she fishes."
I suggest that trying each one's answer and google it,I think you will learn more by yourself.
I am sorry for my poor English.
Good Luck!
|
|
|
|
|
Hi,
I fail to see what MultiThread is bringing, it only exposes some methods of Thread.
BTW: it is a bad idea to abort a Thread, threads should be canceled in a cooperative way as much as possible; and Thread.Suspend is obsolete.
Anyway, the heart of the matter will be reading and timing the COM ports as accurately as possible, which depends on the protocol or message format being used.
|
|
|
|
|
Is something like this what you are looking for? (this example will allow you to read as many files as you like)
using System;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace MultiThreadedFileRead
{
public partial class Form1 : Form
{
private readonly object _syncRoot = new object();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
listBox1.Items.Add(openFileDialog1.FileName);
}
}
private void button2_Click(object sender, EventArgs e)
{
foreach (object file in listBox1.Items)
{
ThreadPool.QueueUserWorkItem(ThreadFunc, file);
}
}
private void WouldBeEventHandler(string s)
{
if (InvokeRequired)
{
Action<string> d = WouldBeEventHandler;
BeginInvoke(d, new object[]{s});
return;
}
lock (_syncRoot)
{
listBox2.Items.Add(s);
}
}
private void ThreadFunc(object state)
{
string filename = state as string;
if (!string.IsNullOrEmpty(filename))
{
using (StreamReader fs = File.OpenText(filename))
{
while (!fs.EndOfStream)
{
WouldBeEventHandler(fs.ReadLine());
Application.DoEvents();
}
}
}
}
}
}
|
|
|
|
|
thanks ... this is ok, but if i need to process in real time (string in file passed from PORT COM in real time...)?
Alex
|
|
|
|
|
This is a serialport example, since you keep mentioning COM PORTS I am supposing this is what you are looking for. I will be happy to help out more, but if this still isn't what you need, a better description of what you need in is order.
using System;
using System.IO.Ports;
using System.Threading;
using System.Windows.Forms;
namespace MultiThreadedFileRead
{
public partial class Form1 : Form
{
private readonly object _syncRoot = new object();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.DataReceived += SerialPort1DataReceived;
serialPort2.DataReceived += SerialPort2DataReceived;
serialPort3.DataReceived += SerialPort3DataReceived;
}
private void SerialPort1DataReceived(object sender, SerialDataReceivedEventArgs e)
{
ThreadPool.QueueUserWorkItem(ThreadFunc, sender);
}
private void SerialPort2DataReceived(object sender, SerialDataReceivedEventArgs e)
{
ThreadPool.QueueUserWorkItem(ThreadFunc, sender);
}
private void SerialPort3DataReceived(object sender, SerialDataReceivedEventArgs e)
{
ThreadPool.QueueUserWorkItem(ThreadFunc, sender);
}
private void ThreadFunc(object state)
{
SerialPort port = state as SerialPort;
if (port != null)
{
try
{
}
catch (Exception)
{
}
}
}
}
}
|
|
|
|
|
Hi,
I am passing a VBScript Object to a C# assembly and am getting the following error output:
"Unable to cast COM object of type 'Agents.AgentClass' to interface type 'Agents._Agent'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{315DF678-45D7-4A60-9A50-C9E83672A5E5}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
I'd appreciate it if someone can explain what is going on here and how I can fix it? I am confused...
Note: I have tried changing the method header to accept type Agents._Agent but that causing the method call in vbscript to fail completely. Changing the type to Agents.Agent (another available type) generates a similar error.
Kind Regards,
Dave
Regards,
Dave
|
|
|
|
|
Hi,
I see there's no reply to this. Do I need to provide more information?
Regards,
Dave
|
|
|
|
|
That error indicates that it doesn't know what an Agent is. I assume that it's correctly installed, registered, and that you can create an agent using VBScript.
Does the C# assembly have references to the correct versions of the AgentObjects.dll and AxAgentObjects.dll?
I are Troll
|
|
|
|
|
[^]
This Might be helpful for you
|
|
|
|