本文整理汇总了C#中MainForm.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# MainForm.Invoke方法的具体用法?C# MainForm.Invoke怎么用?C# MainForm.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MainForm
的用法示例。
在下文中一共展示了MainForm.Invoke方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: read_SGG_data
//Зчитування даних з файлу .SGG
public static double[][] read_SGG_data(string folder, MainForm.setProgressDel d)
{
System.IO.FileInfo fi = new FileInfo(folder);
folder = fi.DirectoryName;
List<string> files = new List<string>();
foreach (var file in System.IO.Directory.GetFiles(folder))
{
var f = new FileInfo(file);
if (f.Extension.Equals(".SGG",System.StringComparison.CurrentCultureIgnoreCase)) { files.Add(file); };
}
List<double[]> myList = new List<double[]>(getLines(files[0]));
if (files.Count > 0) {
foreach (string filename in files)
{
string[] lines = System.IO.File.ReadAllLines(filename);
var x= Parallel.For (0,lines.Length,(i)=>{
double[] temp = null;
double lat = 0; int l = 0;
string[] line = null;
lock (lines)
{
line = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
if (line.Length > 20)
{
lat = double.Parse(line[3]);
//if (lat < 0) lat += 360;
lat = MathFunc.deg2rad(lat);
temp = new double[] { double.Parse(line[1]), MathFunc.deg2rad(90 - double.Parse(line[2])), lat, double.Parse(line[6]) };
if (Math.Abs( temp[1]) < Math.PI && Math.Abs(temp[2]) < 2D * Math.PI)
{
lock (myList) {myList.Add(temp);}
}
else
{
System.Windows.Forms.MessageBox.Show("Помилка в лінії номер " + i.ToString());
}
l++;
if (Math.Round(l / 20000D) == (double)l/20000D) { d.Invoke(l / lines.Length, 1, "Обробка файлу вимірюваннь"); };
}
});
}
};
return myList.ToArray();
}
示例2: readDenceMatrixFromBinFile
public static MathNet.Numerics.LinearAlgebra.Double.DenseMatrix readDenceMatrixFromBinFile(string file,MainForm.setProgressDel d)
{
string[] meta = System.IO.File.ReadAllLines(file + ".metainfo");
System.IO.FileStream fs = new System.IO.FileStream(file,System.IO.FileMode.Open);
System.IO.BinaryReader br = new System.IO.BinaryReader(fs,System.Text.Encoding.Default);
int cols = int.Parse(meta[1]);
int rows = int.Parse(meta[3]);
MathNet.Numerics.LinearAlgebra.Double.DenseMatrix dm = new MathNet.Numerics.LinearAlgebra.Double.DenseMatrix(rows,cols);
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
dm[i, j] = br.ReadDouble();
}
d.Invoke(br.BaseStream.Position / br.BaseStream.Length, 1, "Завантаження");
}
br.Close();
fs.Close();
return dm;
}
示例3: UpdateGUI
public static void UpdateGUI(MainForm form, ProgressState progress = null)
{
int i = 0;
int count = Program.Context.Movies.Distinct().Count();
float perc = 100 / (float)count;
foreach (Movie file in Program.Context.Movies.Where(p => p.Status == Types.ItemStatus.Synced).OrderBy(p => p.Title).Include(p => p.Art).Include(p => p.Genres))
{
progress.SetSubText("(" + (i+1) + "/" + Program.Context.Movies.Count() + ") " + file.Title);
form.scanningBackgroundWorker.ReportProgress(progress.Value, progress);
form.Invoke(new Action(() =>
{
PosterCard pc = form.MovieCards.ContainsKey(file.ImdbId) ? form.MovieCards[file.ImdbId] : new PosterCard();
pc.Title = file.Title + (file.Year.HasValue ? $" ({file.Year.Value})" : "");
pc.Synopsis = file.Plot;
pc.Genres = "Genres: " + string.Join(", ", file.Genres.Select(p => p.Name));
pc.Rating = "Rating: " + (file.Rating?.Name);
if (!string.IsNullOrWhiteSpace(file.Art?.CachePath))
pc.Image = Bitmap.FromFile(file.Art.CachePath);
if (!form.MovieCards.ContainsKey(file.ImdbId))
{
pc.Dock = DockStyle.Fill;
form.tlOverview.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, perc));
form.tlOverview.Controls.Add(pc, i++, 0);
form.MovieCards.Add(file.ImdbId, pc);
}
pc.Movie = file;
pc.CustomClick += form.Poster_click;
}));
}
}
示例4: SelectTab
protected static void SelectTab(MainForm form, int index)
{
form.Invoke(new Action(() =>
{
form.vcHome.SelectTab(index);
}));
}
示例5: loadFromFile
//завантаження моделі з файлу "file"
public void loadFromFile(string file, MainForm.setProgressDel d)
{
if (System.IO.File.Exists(file)){
setLine();
System.IO.TextReader tr = new System.IO.StreamReader(file);
string line = null;
string[] line_a = null;
int l = 0;
string s = " \t"; bool nfl = true;
while( nfl && tr.Peek()!=(-1)){
l++;
line = tr.ReadLine();
line_a = line.Split(s.ToArray<char>(),StringSplitOptions.RemoveEmptyEntries);
if (line_a.Length > 4 && line_a[0].Equals("gfc", System.StringComparison.CurrentCultureIgnoreCase) && (line_a[1].Equals("0") || line_a[1].Equals("2")) && line_a[2] == "0")
{nfl = false;}
else if (line_a.Length == 2) {
if (line_a[0].Equals("earth_gravity_constant")) { this.model_GM = double.Parse(line_a[1].Replace('D', 'e'), System.Globalization.NumberStyles.Any); }
if (line_a[0].Equals("radius")) { this.model_a = double.Parse(line_a[1].Replace('D', 'e'), System.Globalization.NumberStyles.Any); }
//if (line_a[0].Equals("max_degree")) { this.maxDegree = int.Parse(line_a[1].Replace('D', 'e'), System.Globalization.NumberStyles.Any); if (this.maxDegree > this.c_coef.Length) { GravityModel gmn = new GravityModel(maxDegree); c_coef=gmn.c_coef; s_coef=gmn.s_coef; gmn = null; }; }
};}
int n = 0, m = 0, max_n = 0,progress=5, cur_p=0;
while ((line_a.Length > 4))
{
if (line_a[0].Equals("gfc", System.StringComparison.CurrentCultureIgnoreCase))
{
n = int.Parse(line_a[1]); if (n > max_n) { max_n = n; };
m = int.Parse(line_a[2]);
if (n <= maxDegree && m <= n)
{
this.c_coef[n][m] = double.Parse(line_a[3].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any);
this.s_coef[n][m] = double.Parse(line_a[4].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any);
}
if (((System.IO.StreamReader)tr).BaseStream.Position < ((System.IO.StreamReader)tr).BaseStream.Length)
{
line_a = tr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double p = (double)((System.IO.StreamReader)tr).BaseStream.Position / (double)((System.IO.StreamReader)tr).BaseStream.Length;
if (p > cur_p/100d) { cur_p += progress; d.Invoke((int)(p*100), 100, "Завантаження моделі"); }
}
else { this.maxDegree = max_n; break; }
}
else if (line_a[0].Equals("gfct", System.StringComparison.CurrentCultureIgnoreCase) && line_a.Length>=8) {
n = int.Parse(line_a[1]);
m = int.Parse(line_a[2]);
if (n <= maxDegree && m <= n)
{
double[] gfct = new double[]{ double.Parse(line_a[3].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any),double.Parse(line_a[4].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any)};
string da = line_a[7];
DateTime date = new DateTime(int.Parse(da.Substring(0, 4)), int.Parse(da.Substring(4, 2)), int.Parse(da.Substring(6, 2)));
double t_t0 = (DateTime.Today - date).Days / 365d;
line_a = tr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double[] trnd = new double[] {double.Parse(line_a[3].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any),double.Parse(line_a[4].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any)};
line_a = tr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double[] asin1 = new double[] { double.Parse(line_a[3].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any), double.Parse(line_a[4].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any) };
line_a = tr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double[] acos1 = new double[] { double.Parse(line_a[3].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any), double.Parse(line_a[4].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any) };
line_a = tr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double[] asin2 = new double[] { double.Parse(line_a[3].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any), double.Parse(line_a[4].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any) };
line_a = tr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double[] acos2 = new double[] { double.Parse(line_a[3].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any), double.Parse(line_a[4].Replace('d', 'e').Replace('D', 'e'), System.Globalization.NumberStyles.Any) };
this.c_coef[n][m] = gfct[0] + trnd[0] * t_t0 + asin1[0] * Math.Sin(Math.PI * 2f * t_t0) + acos1[0] * Math.Cos(Math.PI * 2f * t_t0) + asin2[0] * Math.Sin(Math.PI * t_t0) + acos2[0] * Math.Cos(Math.PI * t_t0);
this.s_coef[n][m] = gfct[1] + trnd[1] * t_t0 + asin1[1] * Math.Sin(Math.PI * 2f * t_t0) + acos1[1] * Math.Cos(Math.PI * 2f * t_t0) + asin2[1] * Math.Sin(Math.PI * t_t0) + acos2[1] * Math.Cos(Math.PI * t_t0);
}
if (((System.IO.StreamReader)tr).BaseStream.Position < ((System.IO.StreamReader)tr).BaseStream.Length)
{
line_a = tr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
else { this.maxDegree = n; break; }
};
} ;
tr.Close();
tr.Dispose();
}
}
示例6: getGeoidHeightAndAnomalys
public static double[][] getGeoidHeightAndAnomalys(ReferenceSystem rs, GravityModel model, List<double[]> grid, System.Threading.CancellationToken ct,System.Threading.CancellationToken ct2, NormalGammaFormula gamma_0_formula = NormalGammaFormula.Somigliana, MainForm.setProgressDel d = null)
{
GravityModel gm;
if (model.model_a != rs.a || model.model_GM != rs.GM) { gm = new GravityModel(model.rescaleModel(rs), rs.a, rs.GM); } else { gm = new GravityModel(model, model.model_a, model.model_GM); };
gm = getDisturbingModel(rs, gm);
double[] heights = new double[grid.Count];
double[] anomaly = new double[grid.Count];
int[][] t_nm = MathFunc.get_nm(gm.maxDegree);
double[] legendrePolys_old = null; double point_old = double.MinValue; object locker = new object(), locker2 = new object();
int position = 0;
int count = grid.Count, position_p = (rs.maxDegree<150)?(int)Math.Round(0.01d * count):5;
ParallelOptions po = new ParallelOptions();
po.MaxDegreeOfParallelism = Environment.ProcessorCount;
po.CancellationToken = ct;
try
{
Parallel.For(0, grid.Count,po, (pointIndex) =>
{
Label1: if (ct2.IsCancellationRequested) { System.Threading.Thread.Sleep(1000); } else { goto label2; }
goto Label1;
label2: double gamma_0 = 0, B = 0, r = 0;
double[] legendrePolys = null;
double[] point = grid[pointIndex];
lock (locker2)
{
if (point_old != double.MinValue)
{
if (point[0] == point_old)
{
legendrePolys = new double[legendrePolys_old.Length];
legendrePolys_old.CopyTo(legendrePolys, 0);
}
MathFunc.getLegendre(rs.maxDegree, point[0], out legendrePolys);
legendrePolys_old = new double[legendrePolys.Length];
legendrePolys.CopyTo(legendrePolys_old, 0);
point_old = point[0];
}
else
{
MathFunc.getLegendre(rs.maxDegree, point[0], out legendrePolys);
legendrePolys_old = new double[legendrePolys.Length];
legendrePolys.CopyTo(legendrePolys_old, 0);
point_old = point[0];
}
}
B = MathFunc.convertThethaToB(point[0], rs);
r = MathFunc.getGeocentrDistanceToPointOnElips(rs, B);
if (gamma_0_formula == NormalGammaFormula.Somigliana)
{ gamma_0 = rs.gamma_a * (1d + rs.k * Math.Pow(Math.Sin(B), 2d)) / Math.Sqrt(1d - rs.firstExcentricity_2 * Math.Pow(Math.Sin(B), 2d)); }
else { gamma_0 = 9.78030d * (1d + 0.005302 * Math.Pow(Math.Sin(B), 2d) - 0.000007 * Math.Pow(Math.Sin(2d * B), 2d)); }
double a1, a2_x = rs.a / r, a2_t, a3, cosMlambda, sinMlambda, a1_a, a2_a = 0, a2 = 0, a2_x_m = a2_x;
a1 = rs.GM / (r * gamma_0);
a1_a = rs.GM / (r * r);
int az = 0;
for (int n = 0; n < rs.maxDegree; n++)
{
int x = (n == 0) ? 0 : -1;
a3 = 0;
az += (n - 1) + 1;
for (int m = 0; m <= n; m++)
{
cosMlambda = Math.Cos(m * point[1]);
sinMlambda = Math.Sin(m * point[1]);
a3 += (gm.c_coef[n][m] * cosMlambda + gm.s_coef[n][m] * sinMlambda) * legendrePolys[az + (n - m)];
}
if (n > 1) { a2_x *= a2_x_m; a2_t = a2_x; } else { a2_t = Math.Pow(a2_x, n); };
a2 += a2_t * a3;
a2_a += a2_t * (n - 1) * a3;
}
double tmp_h = a1 * a2, tmp_a = a1_a * a2_a*1e5;
lock (heights)
{ heights[pointIndex] =tmp_h; }
lock (anomaly)
{ anomaly[pointIndex] = tmp_a; }
if (d != null)
{
position++;
if (position > position_p) { lock (locker) { position_p += position_p; }; d.Invoke(position, count, "Обчислено висоти для точок: "); };
if (position >= count) { d.Invoke(0, 1, ""); };
}
});
}
catch (OperationCanceledException)
{
return new double[2][];
}
return new double[][] { heights, anomaly };
}
示例7: getGeoidHeight
//Обчислення висот геоїда для сітки (в метрах) формула обчислення нормальної сили ваги "gamma_0_formula" (за замовчуванням ф-ла Сомільяни)
public static double[] getGeoidHeight(ReferenceSystem rs, GravityModel model, List<double[]> grid, NormalGammaFormula gamma_0_formula = NormalGammaFormula.Somigliana, MainForm.setProgressDel d = null)
{
GravityModel gm;
if (model.model_a != rs.a || model.model_GM != rs.GM) { gm = new GravityModel(model.rescaleModel(rs), rs.a, rs.GM); } else { gm = new GravityModel(model, model.model_a, model.model_GM); };
gm = getDisturbingModel(rs, gm);
double[] heights = new double[grid.Count];
int[][] t_nm = MathFunc.get_nm(gm.maxDegree);
double[] legendrePolys_old = null; double point_old = double.MinValue; object locker = new object(), locker2 = new object();
int position = 0;
int count =grid.Count,position_p=(int)Math.Round(0.01d*count);
Parallel.For(0, grid.Count, (pointIndex) => {
double gamma_0 = 0, B = 0, r = 0;
double[] legendrePolys = null;
double[] point = grid[pointIndex];
lock (locker2)
{
if (point_old != double.MinValue)
{
if (point[0] == point_old)
{
legendrePolys = new double[legendrePolys_old.Length];
legendrePolys_old.CopyTo(legendrePolys, 0);
}
MathFunc.getLegendre(gm.maxDegree, point[0], out legendrePolys);
legendrePolys_old = new double[legendrePolys.Length];
legendrePolys.CopyTo(legendrePolys_old, 0);
point_old = point[0];
}
else {
MathFunc.getLegendre(gm.maxDegree, point[0], out legendrePolys);
legendrePolys_old = new double[legendrePolys.Length];
legendrePolys.CopyTo(legendrePolys_old,0);
point_old = point[0];
}
}
B = MathFunc.convertThethaToB(point[0], rs);
r=MathFunc.getGeocentrDistanceToPointOnElips(rs,B);
if (gamma_0_formula == NormalGammaFormula.Somigliana)
{gamma_0 = rs.gamma_a * (1d + rs.k * Math.Pow(Math.Sin(B), 2d)) / Math.Sqrt(1d - rs.firstExcentricity_2 * Math.Pow(Math.Sin(B), 2d));}
else { gamma_0 = 9.78030d * (1d + 0.005302 * Math.Pow(Math.Sin(B), 2d) - 0.000007 * Math.Pow(Math.Sin(2d * B), 2d)); }
double a1, a2=0, a3,cosMlambda,sinMlambda;
a1 = rs.GM / (r * gamma_0);
for (int n = 0; n < gm.maxDegree; n++) {
a3 = 0;
for (int m = 0; m <= n; m++){
cosMlambda = Math.Cos(m * point[1]);
sinMlambda = Math.Sin(m * point[1]);
lock (gm)
{a3 += (gm.c_coef[n][m] * cosMlambda + gm.s_coef[n][m] * sinMlambda) * legendrePolys[MathFunc.getArraySize(n - 1) + (n - m)];}
}
a2 += Math.Pow(rs.a / r, n)*a3;
}
lock (heights)
{heights[pointIndex] = a1 * a2;}
if (d!=null)
{
position++;
if (true || position > position_p) { lock (locker) { position_p += position_p;}; d.Invoke(position,count,"Обчислено висоти для точок: ");};
if (position >= count) { d.Invoke(0, 1, ""); };
}
});
return heights;
}