I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
In this article, I will show you how to fix computer hanging problems. Generally, we all know about "Not Responding" problem. When processor takes time to execute the process then thats type of problem occurs. By using this article, I will resolve this issue.
Windows Form Design:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
private readonly SynchronizationContext synchronizationContext;
private DateTime previousTime = DateTime.Now;
public Form1()
{
InitializeComponent();
synchronizationContext = SynchronizationContext.Current;
}
private void button1_Click(object sender, EventArgs e)
{
for (var i = 0; i <= 1000000; i++)
{
label1.Text = @"Count : " + i;
}
}
private async void button2_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
var count = 0;
await Task.Run(() =>
{
for (var i = 0; i <= 1000000; i++)
{
UpdateUI(i);
count = i;
}
});
label1.Text = @"Count : " + count;
button1.Enabled = true;
button1.Enabled = false;
}
public void UpdateUI(int value)
{
var timeNow = DateTime.Now;
//Here we only refresh our UI each 50 ms
if ((DateTime.Now - previousTime).Milliseconds <= 50) return;
//Send the update to our UI thread
synchronizationContext.Post(new SendOrPostCallback(o =>
{
label1.Text = @"Count : " + (int)o;
}), value);
previousTime = timeNow;
}
}
}
Windows Form Design:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
private readonly SynchronizationContext synchronizationContext;
private DateTime previousTime = DateTime.Now;
public Form1()
{
InitializeComponent();
synchronizationContext = SynchronizationContext.Current;
}
private void button1_Click(object sender, EventArgs e)
{
for (var i = 0; i <= 1000000; i++)
{
label1.Text = @"Count : " + i;
}
}
private async void button2_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
var count = 0;
await Task.Run(() =>
{
for (var i = 0; i <= 1000000; i++)
{
UpdateUI(i);
count = i;
}
});
label1.Text = @"Count : " + count;
button1.Enabled = true;
button1.Enabled = false;
}
public void UpdateUI(int value)
{
var timeNow = DateTime.Now;
//Here we only refresh our UI each 50 ms
if ((DateTime.Now - previousTime).Milliseconds <= 50) return;
//Send the update to our UI thread
synchronizationContext.Post(new SendOrPostCallback(o =>
{
label1.Text = @"Count : " + (int)o;
}), value);
previousTime = timeNow;
}
}
}
Comments
Post a Comment