Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Xamarin.Android C#: I have several void where I need to have the AddOnSuccessListener, the problem is that they all go to the same OnSuccess.
How can I have 3 or more AddOnSuccessListener with different OnSuccess for each void?
Example of voids:
query.Get (). AddOnSuccessListener (this);
database.Collection ("Users"). Document (DocID) .Get ().
AddOnSuccessListener (this);
Ideas?
A Get() call returns a task. While a task can have multiple listeners, you can't chain them together like you're trying.
So you'll want to capture the task, and then call AddOnSuccessListener multiple times.
var task = database.Collection("Users").Document(DocID).Get();
task.AddOnSuccessListener(this);
task.AddOnSuccessListener(...);
task.AddOnSuccessListener(...);
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
[how to call an integer as it is changing when loop is running i want print and calculate every single time loop runs hope you understand my question
You need to change the line
total = perunit * quanitity
to
total += perunit * quantity
this will add the result to total, not override total every time.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I 've a doubt that researching I couldn't solve.
I want to pass a parameter using a var type to this method:
public static List<T[]> sortRequests<T>(List<T> _requests)
{
return null;
}
And I am calliinf the method here:
//Note: Thats code corresponds from an HttpRest service.
var _requests = await _requestService.Search(new SearchRequestSpecificationMapper().Map(searchRequestsViewModel));
var requests = sortRequests(_requests);
So VS 2015 is reporting about an error when I call the sortRequest() method.
Can anybody help me please?
Thank you very much in advance.
_requests is (presumably) not a List<T>.
You might be able to make it into a List<T> by caling ToList:
var requests = sortRequests(_requests.ToList());
However, I can't be certain without knowing more about your code, especially what the Search and Map functions do.
NOTE
Please be aware that there is no such thing as a var type in C#. var is just a bit of syntactic sugar that means "This variable has the type of whatever I assign to it when I declare it" - it's no different to just declaring it as the correct type.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want a Method in C# which is going to make a break for 5 Seconds between 2 lines of codes.
Thread.sleep(5000);
isn't working because the rest of the code does also make a break. Have you got any Idea how to solve this?
falling.timespeed = 0.6f;
falling.fallingl = -50f;
// here I want a break for 5 Seconds
falling.timespeed = 1f;
falling.fallingl = -200f;
Are you familiar with the asynchronous features in modern c#?
In c# 5 and above:
async Task DoSomeWork()
{
// Do the first part of the work
await Task.Delay(5000); // Asynchronously wait for a 5 second timer to expire.
// Do the second part of the work
}
Note that, depending on the threading context that you call this method, part 2 may be executed on the same thread, or a different thread.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a database field called "PIECE" which datatype is NUMERIC(11,0),
I must convert this field to a long-datatype.
This without any luck or succes, I'll keep getting the same error:
Wrong conversion...
I tried the next things:
(long)PIECE
long.Parse(PIECE.ToString().Trim())
But I'm still having the wrong conversion message,
is here someone who can help me?
This will do it:
var result = Convert.ToInt64(PIECE);
https://msdn.microsoft.com/en-us/library/0zahhahw(v=vs.110).aspx
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I thought I could do i straight forward, but maybe there is something wrong with my setup? I'm trying to download a string in my app for logging in:
private async void DoLogin()
{
HttpClient client = new HttpClient();
string response = await client.GetStringAsync(Config.SERVER_URL + "/Login/");
All logic is removed, im going to add headers and so on, but VS2012 will no allow me to await that response.
I tried to follow the code from here, but in my case I only get Cannot await 'System.Threading.Tasks.Task<string'.
Why is that? Should'nt GetStringAsync simply return me a string? It returns a Task<string>, but do I have to wrap it in a method?
Your code is perfectly fine. However: In order to use async / await in portable class libaries you need to add the NuGet package Microsoft.Bcl.Async to your project.
Also please note the comment of Servy to use the return type Task instead of void.