How can I set the position of my datagrid scrollbar in my winforms app?

You don’t actually interact directly with the scrollbar, rather you set the FirstDisplayedScrollingRowIndex. So before it reloads, capture that index, once it’s reloaded, reset it to that index. EDIT: Good point in the comment. If you’re using a DataGridView then this will work. If you’re using the old DataGrid then the easiest way to do … Read more

BackgroundWorker RunWorkerCompleted Event

If the BackgroundWorker was created from the UI thread, then the RunWorkerCompleted event will also be raised on the UI thread. If it was created from a background thread, the event will be raised on an undefined background thread (not necessarily the same thread, unless you’re using a custom SynchronizationContext). Interestingly, this doesn’t seem to … Read more

Start a .Net Process as a Different User

Can you try something like this: Start a new Process as another user Code sample: System.Diagnostics.Process proc = new System.Diagnostics.Process(); System.Security.SecureString ssPwd = new System.Security.SecureString(); proc.StartInfo.UseShellExecute = false; proc.StartInfo.FileName = “filename”; proc.StartInfo.Arguments = “args…”; proc.StartInfo.Domain = “domainname”; proc.StartInfo.UserName = “username”; string password = “user entered password”; for (int x = 0; x < password.Length; x++) … Read more

How to map JSON to C# Objects

You can use Json.NET to deserialize your json string as (with some modifications to your classes) var yourObject = JsonConvert.DeserializeObject<Root>(jsonstring); public class Root { public Profile[] Profile; } public class Profile { public string Name { get; set; } public string Last { get; set; } public Client Client { get; set; } public DateTime … Read more

Why does closing a console that was started with AllocConsole cause my whole application to exit? Can I change this behavior?

Ah, yes, this is one of the caveats of using the Windows console subsystem. When the user closes the console window (regardless of how the console was allocated), all of the processes that are attached to the console are terminated. That behavior makes obvious sense for console applications (i.e., those that specifically target the console … Read more

What does AsSelf do in autofac? [duplicate]

Typically you would want to inject interfaces, rather than implementations into your classes. But let’s assume you have: interface IFooService { } class FooService { } Registering builder.RegisterType<FooService>() allows you to inject FooService, but you can’t inject IFooService, even if FooService implements it. This is equivalent to builder.RegisterType<FooService>().AsSelf(). Registering builder.RegisterType<FooService>().As<IFooService>() allows you to inject IFooService, … Read more

Generate access token with IdentityServer4 without password

[HttpPost(“loginas/{id}”)] [Authorize(Roles = “admin”)] public async Task<IActionResult> LoginAs(int id, [FromServices] ITokenService TS, [FromServices] IUserClaimsPrincipalFactory<ApplicationUser> principalFactory, [FromServices] IdentityServerOptions options) { var Request = new TokenCreationRequest(); var User = await userManager.FindByIdAsync(id.ToString()); var IdentityPricipal = await principalFactory.CreateAsync(User); var IdServerPrincipal = IdentityServerPrincipal.Create(User.Id.ToString(), User.UserName, IdentityPricipal.Claims.ToArray()); Request.Subject = IdServerPrincipal; Request.IncludeAllIdentityClaims = true; Request.ValidatedRequest = new ValidatedRequest(); Request.ValidatedRequest.Subject = Request.Subject; Request.ValidatedRequest.SetClient(Config.GetClients().First()); Request.Resources … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)