|
I have one last thing. I'm not familiar with bash, is it a command line program?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes, I think it's some kind of command prompt that is standard for Unix systems, but it exists for Windows also. I've seen some of my colleagues (those that prefer typing over interacting with GUI:s) type
$ git.exe checkout develop when they want to checkout in Git.
|
|
|
|
|
Bingo! That must be why you're not finding any Windows.
I can think of two possibilities at this point.
1. It might be that you need to find bash's parent process and enumerate the windows of that process instead.
2. It might be that the Linux Subsystem is interfering somehow.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
When I closed my bash.exe command prompt, I could see that the following processes disappeared: backgroundTaskHost, bash, conhost, git-bash, mintty and RuntimeBroker. When I tried mintty instead of bash, then it worked great! Again, thanks for your help!
|
|
|
|
|
Happy to help!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi all I have this method in a class which tries to get an access token from Azure Active Directory - it works if I use it in a Net Core app but hangs forever when I try to use it in a Winforms app
private async Task GetAccessToken()
{
string Instance = Utils.GetAppConfigSetting("Instance");
string TenantID = Utils.GetAppConfigSetting("TenantID");
string ClientID = Utils.GetAppConfigSetting("ClientID");
string ClientSecret = Utils.GetAppConfigSetting("ClientSecret");
string BaseAddress = Utils.GetAppConfigSetting("BaseAddress");
string ResourceID = Utils.GetAppConfigSetting("ResourceID");
string APIServer = Utils.GetAppConfigSetting("APIServer");
string Authority = String.Format(CultureInfo.InvariantCulture,Instance, TenantID);
this.App = ConfidentialClientApplicationBuilder.Create(ClientID)
.WithClientSecret(ClientSecret)
.WithAuthority(new Uri(Authority))
.Build();
this.ResourceIds = new string[] { ResourceID };
this.Result = await this.App.AcquireTokenForClient(this.ResourceIds).ExecuteAsync();
this.AccessToken = this.Result.AccessToken;
this.Client.Authenticator = new JwtAuthenticator(this.AccessToken);
}
// I call it with this code
this.GetAccessToken().GetAwaiter().GetResult();
there is no error it just hangs - any ideas ?
Edit
It must be the UI thread in Winforms as I just tried the same code in a Console App and it worked perfectly
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
modified 31-Jul-20 9:51am.
|
|
|
|
|
pkfox wrote: It must be the UI thread in Winforms
Correct. Your async method tries to return to the current "execution context" after the await . In a WinForms app, when the async method was called from the UI thread, it tries to return to the UI thread. But you've blocked the UI thread by trying to execute the async method synchronously:
this.GetAccessToken().GetAwaiter().GetResult(); Therefore, the async method can never complete.
If you're not accessing the UI from your GetAccessToken method, you can add .ConfigureAwait(false) to your ExecuteAsync call, so that the rest of the method can complete on a thread-pool thread:
this.Result = await this.App.AcquireTokenForClient(this.ResourceIds).ExecuteAsync().ConfigureAwait(false); Otherwise, you'll need to find a way to avoid blocking the UI thread. You'd need to make the calling method async . However, you want to avoid async void methods[^]. A simple solution is to move the code into a task-returning async method, and assign the returned task to a "discard" variable to avoid the compiler warning.
Old code, don't use:
private void ButtonClick(object sender, EventArgs e)
{
this.GetAccessToken().GetAwaiter().GetResult();
} Bad fix, don't use:
private async void ButtonClick(object sender, EventArgs e)
{
await this.GetAccessToken();
} Better fix:
private void ButtonClick(object sender, EventArgs e)
{
_ = SomeMethodAsync();
}
private async Task SomeMethodAsync()
{
await this.GetAccessToken();
}
ConfigureAwait FAQ | .NET Blog[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard should I leave the code as is in GetAccessToken() ? I got around it by using a BackGroundWorker but I think maybe your way is better
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
If you're moving the code to a task-returning async method, and getting rid of the .GetAwaiter().GetResult() call in favour of await ing the operation, then the GetAccessToken code should be fine.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How will I know when the job has finished ?
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
That depends what you're trying to do.
If you just want to run some code immediately after GetAccessToken has finished, you can put it in the new async method after the await this.GetAccessToken(); line.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Except GetAccessToken() is in a separate class from the form
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
That doesn't matter. You have a task-returning async method which calls it, and put any code you need to run after it's returned after the await .
If you need to run code in the form after the async method in another class returns, you also use a task-returning async method, and put the code after the await .
class SomeClass
{
private async Task GetAccessToken() { ... }
public async Task DoSomething()
{
await GetAccessToken();
}
}
class YourForm
{
private SomeClass _someClass;
private void FormLoad(object sender, EventArgs e)
{
_someClass = new SomeClass();
_ = DoSomethingInTheForm();
}
private async Task DoSomethingInTheForm()
{
await _someClass.DoSomething();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard that's pretty much what I've ended up with - brilliant article in the link you posted
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
Hi Richard , thanks for the link lots of good stuff in there - I understand it a lot more now
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
Watching a Video on windows media player will produce black bars on the left and right.
this.MPlayer.stretchToFit = true;
AxWindowsMediaPlayer mPlayer = this.MPlayer;
mPlayer.URL = "Location of a file";
Below attached file output of the code.
Please suggest me how to change the aspect ratio of an Windows media player.
|
|
|
|
|
The "player" itself doesn't resize ... that's what you're expecting. You'd go wonky watching a slideshow.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I am using the VB text editor and want to do some basics in C#. All I want to do is create a list of verbs and have them randomly pair to another list of adjectives to perform a primitive gamertag generator. I am not having a specific problem other than I need an example of this simple function to help me learn and surprisingly I can't find anything maybe because it's too simple...If this is not a good place to learn can someone point me in the right direction because YouTube did not have what I wanted.
|
|
|
|
|
You break the project down into tasks. With each task, the problem becomes more transparent.
Your first task would be to compile your word lists. Then, using C#, read them into memory. That's enough to generate more questions once you start.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Load your verbs into a collection - an array or list, whichever you want.
Do the same with the adjectives
Then create another collection which takes two indexes into the collections: that stores the "used" tags so you don't repeat. A Dictionary<int, int> should do it. Load it with the gamertags that you've actually issued.
Now, to generate a new tag, pick two indexes at random. Check to see if they are already used together. If they aren't, add them, and you have your tag.
If not, generate two more and try again.
Think of it as if you were doing it with a paper and pencil, and you'll see what I mean.
There are more efficient ways (ensuring you can't generate duplicates instead of checking for them) but they are rather more complicated, particularly for a beginner.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am new to .net core and have a question about the functional use of a method that retrieves a single value from a query. Using an MVC pattern, do I need to build a model (entity) for the result?
<pre>public string Line1Today()
{
string line1LbsToday = "";
using (MySqlConnection conn = GetConnection())
{
try
{
conn.Open();
MySqlCommand cmd = new MySqlCommand("select SUM(value) from tbl1", conn);
line1LbsToday = cmd.ExecuteScalar().ToString();
}
catch (System.Exception ex)
{
return ex.ToString();
}
finally
{
conn.Close();
}
}
return line1LbsToday;
}
I would like the return value to be sent to a view with some HTML formatting that I have set up. I realize this is quite a trivial question...but I am stuck...i can return whole table results to views, but I am looking for one single scalar value and can't seem to figure out the right approach. Any help would be greatly appreciated.
|
|
|
|
|
It's business / data access code; a scalar vs a "table result" with which you are familiar. Think of the scalar as a single-column table result, if that helps.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
The thing I am not quite wrapping my head around, is typically I have a model framed out to return values in a table...I define the properties etc...those properties I can then walk through with a for loop and @Html.DisplayTextFor() in a table in the view....
With this, I am just looking to return the results of the query. I can't call the function directly from a view..I think my brain is broken at this point...again I know this is a ridiculously simple ask, but for the life of me, I can't google it, can't make it work with existing knowledge, so I am hopefully asking someone for a bit of a kick in the right direction. Do I need a model that defines the result as a property?
|
|
|
|
|
At the top of the Razor code file (*.cshtml), you specify the model, or the type, that the page requires to do it's job, if any data is needed for that page.
When you define a view model to pass to the page, you're just defining a custom type.
So, if all you're doing is passing in an integer to the page, or a string, at the top of the .cshtml page, you just telling to expect that type:
@model int
or
@model string
Then in your Razor code, you just use Model anywhere you need that value, just like using any other view model class.
To pass that value from your Controller, you just pass whatever that data is, no different than you pass any other object (class instance).
return View(100);
return View("Some string");
return View(myStringVariable)
|
|
|
|
|
Dave, thanks so much for the detailed response! So if my controller has several methods, all returning somethings to view, how should I approach that? Also, I am using a ViewModel because I have multiple models feeding the page. I also have context classes that I use to feed the data as well...
|
|
|
|