Issue
I am kinda new to Xamarin.Android and still have a steep learning curve ;-). But i approached a problem which i don't find a solution even after a few days of googling and YouTube-ing.
Do somebody know how to call a async Task from another Class?
i want to call the public async Task ReadStringAsync() from the class MainActivity. How can i do that?
i want to call this:
class TextfileRead
{
string[] StrData;
String filename = "Arbeitszeiten.txt";
String filepath = "myFileDir";
String fileContent = "";
public async Task<string> ReadStringAsync()
{
var backingFile = Path.Combine(filepath, filename);
if (backingFile == null || !System.IO.File.Exists(backingFile))
{
return "oO, irgendwas ging schief";
}
string line;
using (var reader = new StreamReader(backingFile, true))
{
//string line;
while ((line = await reader.ReadLineAsync()) != null)
{
//return line;
}
}
return line;
}
Solution
In MainActiviy.cs, you could use following ways to call public async Task ReadStringAsync().
public async void getValue()
{
TextfileRead textfileRead = new TextfileRead();
string value = await textfileRead.ReadStringAsync();
}
Answered By - Junior Jiang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.