Question Multiple Method Calling

sumonesaw

New member
Joined
Mar 31, 2016
Messages
2
Programming Experience
Beginner
Hi Guys,


I'm a beginner in C# Language and studying/learning it for past 1 month via Internet.. To make myself understand it clearly skipping theoretical part I'm trying to develop multiple simple things and working on them and finding issues and optimizing codes and learn also..


So I'm stuck on some issues for which I googled and didn't find appropriate answer also I need some expert advice to guide me.


My first issue/query is.


I have created a multiple methods which are in series to do a work
C#:
void button_click()
{
Sort();
await Task.delay // to let my GUI Unfreeze
Replace();
await Task.delay // to let my GUI Unfreeze
Show();
}
void Sort()
{  //code  }
void Replace()
{  //code  }
void Show ()
{  //code  }
So is my above way of calling my method is correct.

My second issue is
C#:
void button_click()
{
Sort();
await Task.delay // to let my GUI Unfreeze
Replace();
await Task.delay // to let my GUI Unfreeze
Show();
}
void Sort()
{  
//code
Fetchdata();
  }
void Replace()
{  
//code
FetchData2();
  }
void Show ()
{  //code  }
void FetchData()
{ //code }
void FetchData2()
{ //code }

In My above code i used some other method calling in a method to parse/find text value from my file in order to use in next method.. But if value is return null then i need it to go to previous method in order to complete code from 1st method correctly. But if i do something like this
void FetchData()
{ //code
if (data1 == null)
Replace();
}
Here it will go to to Replace method and once it is finished it will come out via Fetchdata method and work on next method... {I'm also getting confuse what will happen}

Please Help me as I'm thinking of this and making my self confuse more.

Please and Thanks..
 
Last edited:
With regards to your first question, would it not make more sense to call each of your methods asynchronously via tasks rather than executing them on the UI thread and then trying to "unfreeze" the UI in between?

With regards to your second question, I don't really know what it is. Rather than saying "first method", "second method", "previous method", etc, how about you just lay out, step by step, exactly what method, by name, needs to get executed? If I'm interpreting what you're saying correctly then it seems to me that you could just use a 'do' loop and have the method you're calling return a bool that indicates whether it succeeded or not but I'm not confident of that interpretation.
 
Thanks for Reply.

With regards to your first question, would it not make more sense to call each of your methods asynchronously via tasks rather than executing them on the UI thread and then trying to "unfreeze" the UI in between?
I don't get how to make method asynchronously a little code help would be good for me..

With regards to your second question, I don't really know what it is. Rather than saying "first method", "second method", "previous method", etc, how about you just lay out, step by step, exactly what method, by name, needs to get executed? If I'm interpreting what you're saying correctly then it seems to me that you could just use a 'do' loop and have the method you're calling return a bool that indicates whether it succeeded or not but I'm not confident of that interpretation.

Thanks for bool i didn't thought of that as i was trying if(data == null) but my question still remains same.

Go To method1 and calling fetchdata inside method1 and if fetchdata returns null then go to method1 else go to method2 similarly after method2 is called go to fetchdat1 inside method2 and if fetchdata1 returns null then go to method1 else go to method3... What would be correct way to do this.
 
Back
Top Bottom