|
Hello friends,
I'm am 4 months new to C#, so my question is probably quite simple but has me baffled . It seems that my methods overlap eachother and donot execute one at time for example. I have a method called actions and from within that method i call several other methods like;
private void actions()
{
1. PlayAudioFile01(); //Play Audio file
2. MovePicture(xpos,ypos,delay); //moves pic to given coordinates with delay after each pixel move;
3. LoadfileShowText(arrayPos); // loads text from file into a string array and shows text of designated arrayPositon in a textbox.
4. PlayAudioFile02();
}
Why would method three execute before method two is finished? Also Method 2 gets interrupted by method 4. The picture will stop moving before it gets to its destination and PlayAudioFile02() will start playing my second file. What am i missing? Shouldn't method two finish performing beform the next methods begin? Any suggestions will prolong my days many! Thank you
Basement Dweller
|
|
|
|
|
Hi,
Are you using multi-threading for the same ? I faced this situation in a multi-threaded application. Actually i started the threads but didnt synchronized them. Are you doing something like that ?
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
The only possible reason is that you have them executing threads. Otherwise, it's not really possible. Stuff like 'play audio file', are probably calling a control like WMP, which means that it starts a thread, quite possibly.
Basement Dweller wrote: The picture will stop moving before it gets to its destination and PlayAudioFile02() will start playing my second file
Are you sure if you take out the call to play audio file 2, your picture would move any differently ?
It's hard to comment further without seeing the code.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
hi,
just now i read about unsafe blocks. i got one doubt.......we will use this block to write unsafe (unmanaged) code...is it correct??
if so, please anyone tell me why should we require to write unmanaged code in .net?
as per my knowledge COM, API functions are not managed by CLR, i mean we can say these are unmanaged code functions. but .net where we use these unsafe blocks?
thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Rahithi wrote: we will use this block to write unsafe (unmanaged) code...is it correct??
No. Unsafe means code that accesses pointers directly.
Rahithi wrote: if so, please anyone tell me why should we require to write unmanaged code in .net?
Image processing is one area where things are a lot faster if you access the memory directly.
Rahithi wrote: as per my knowledge COM, API functions are not managed by CLR, i mean we can say these are unmanaged code functions. but .net where we use these unsafe blocks?
Did you read any examples of using unsafe blocks, or did you just read that they were called unsafe, and then come here to ask ? Unsafe has nothing to do with COM, or API functions. You can pinvoke API calls, you don't need unsafe blocks for that.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Greetings! For an application I'm writing, I require to be able to save data to an XML file and, when necessary, be able to import that data into my forms.
I have no problem in writing the data to an XML file. I also have rudimentary familiarity with XMLTextReader in that I can read the name of a node and its value.
However, my question is this:
What would be the best way to go through an existing XML file with a schema similar to that below and fill in values for Object0 to Object "n" in a form?
<RootNode>
<ObjectProperties>
<Object0>
<Property1> A </Property1>
<Property2> B </Property2>
<Property3> C </Property3>
</Object0>
<Object1>
<Property1> D </Property1>
<Property2> E </Property2>
<Property3> F </Property3>
</Object1>
... etc
</ObjectProperties>
</RootNode><
I was wondering if there was a better method than checking for each node name and then filling the appropriate box in the form with the node's value.
What would be a recommended method for doing this?
Thanks!
|
|
|
|
|
Hi,
There are quite a number of options available.
1. Use of XmlSerializer- This would will be beneficial if some class data needs to be stored in XML Format.
2. If the XML document is "Well-Formed" then you can directly read the data from XML to a data set which then you can use to bind to some GUI control.
I think the serialization option will be better for you. For that you will have to write a class for the data to be stored and those all data-types must be serializable. I think you must be using primary data types only. So that wont be a problem.
After you write the class for the data to be stored, you will just need to call Serialize and Deserialize methods of the XmlSerializer class.
Hope all class and method names are correct.
If you want more information about XmlSerializer please check MSDN.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
Hello,
I have two projects (say proj1 and proj2) that are part of one solution. Both of them need to access a resource (.resx) file, which I can only add to one of the projects (say, to proj2). Is there a more graceful way of accessing this resource file (or making it common to both projects) than explicitly loading the assembly that references the .resx file into the one that doesn't? Thank you.
|
|
|
|
|
You should be able to include the common resource file in each project, though you may have to do this by hand-editing the project files (.csproj). For example, if both projects are at a peer level, with the resource file in a parent folder, you could include them in the project files like so:
<br />
<Compile Include="Properties\Settings.Designer.cs"><br />
<AutoGen>True</AutoGen><br />
<DependentUpon>Settings.settings</DependentUpon><br />
<DesignTimeSharedInput>True</DesignTimeSharedInput><br />
</Compile><br />
<EmbeddedResource Include="..\Resource1.resx"><br />
<SubType>Designer</SubType><br />
<Generator>ResXFileCodeGenerator</Generator><br />
<LastGenOutput>..\Resource1.Designer.cs</LastGenOutput><br />
</EmbeddedResource><br />
-Phil
|
|
|
|
|
Excellent! I just tried your solution and it works (not being able to edit the projects' properties in the designer view is a bummer, but editing them manually does the trick). Thank you, Phil!
Vladimir
|
|
|
|
|
Hello,
how do I construct a mathematical formula based on user's TEXT input?
It would be too complicated to explain what do I need to accomplish in my app, but let's just say that there's a textbox on a user form and based on what the user enters into that textbox, further calculation will be done.
E.g. if user enters "a + ( b / 2 )" and "a" and "b" will be recognized/parsed as valid variables with some internal meaning, the app will do certain calculation based on this formula. It would be too cumbersome to try to catch all possible input combinations the user might possible enter.
There must be some standard way on how to do this.
Is there any best practice on how to do this?
Thank you very much for any input,
Michal Kreslik
|
|
|
|
|
There have been several articles on CP about this.
Search keywords could be: symbolic, expression, evaluation
Luc Pattyn
|
|
|
|
|
Thank you very much, you helped me a lot by placing a correct name on the issue.
Thanks,
Michal
|
|
|
|
|
Hi
in php, there is a function called 'Preg_replace();' and i was wondering if i am able to do the same thing in c#?
|
|
|
|
|
Maybe if you explained a bit what it does we could help you.
I have no idea what I just said. But my intentions were sincere.
Poore Design
|
|
|
|
|
|
Hello all,
In vb6 there are properties called scaleX & scaleY for the image or form.
What the equivilant for these properties in C#
Thanks for HELP
|
|
|
|
|
The graphics object offers a scale transform.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I have a windows application with two button and one textarea. the button are start and stop. When I press start I want the program to execute a method x amount of times until I press the stop button. I'm displaying and increment number in the text area and when I run the program it doesn't display anything and it just hands there and I can't click the stop button. How can i fix this and get it to work?
<br />
private void startBtn_Click(object sender, System.EventArgs e)<br />
{<br />
stopBtn.Enabled = true;<br />
startBtn.Enabled = false;<br />
StartService();<br />
<br />
}<br />
<br />
private void stopBtn_Click(object sender, System.EventArgs e)<br />
{<br />
startBtn.Enabled = true;<br />
stopBtn.Enabled = false;<br />
StopService();<br />
<br />
}<br />
<br />
public void StartService()<br />
{<br />
int counter =1;<br />
while (start)<br />
{<br />
status.Text += counter +" test \n"; <br />
<br />
counter++;<br />
Thread.Sleep(5000);<br />
}<br />
<br />
}<br />
public void StopService()<br />
{<br />
start = false;<br />
}<br />
<br />
|
|
|
|
|
You should not execute Thread.Sleep() on the UI thread, since that freezes the UI.
There are two solutions for your problem:
1)
use a separate thread, with a loop and a Thread.Sleep
a while loop seems appropriate, make it while(running)
where running is a bool set true and false by your buttons
2)
use a Windows.Forms.Timer, start and stop it with your buttons
and execute your periodic job in its tick event (without a Thread.Sleep of course).
Luc Pattyn
|
|
|
|
|
thanks Luc for the quick replay, can you give me an example of solution #2?
|
|
|
|
|
Something along these lines maybe (code is not complete!):
using System.Windows.Forms;
class demo {
Timer timer;
int count;
Label myLabel;
public demo() {
timer=new Timer();
timer.Interval=5000;
timer.Tick+=new EventHandler(demo_tick);
}
btnStart_Click(...) {
timer.Start();
}
btnStop_Click(...) {
timer.Stop();
}
void demo_tick(...) {
count++;
myLabel.Text="Tick #"+count;
}
}
This is the simplest solution of the two, but it required the repetitive task
to be short (since it runs on the UI thread). If there is too much work to do,
you should go for a separate thread.
Luc Pattyn
|
|
|
|
|
Thanks a lot Luc, I will give it a try in a few.
|
|
|
|
|
hi
i want to know how to save and retrieve data to/from XML file simple...
can anyone help me ?
thanks
|
|
|
|
|
Take a look at the System.Xml namespace especially XmlDocument , XmlReader and XmlWriter .
"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
|
|
|
|