当我重构一些旧的 C# 代码以使用该库生成文档时Office.Interop,我发现了这一点,因为它使用了 UI 上下文。当从它调用函数时它会阻塞它
例如:
private void btnFooClick(object sender, EventArgs e)
{
bool documentGenerated = chckBox.Checked ? updateDoc() : newDoc();
if(documentGenerated){
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
我决定更改它以减少阻塞 UI:
private async void btnFooClick(object sender, EventArgs e)
{
bool documentGenerated; = chckBox.Checked ? updateDoc() : newDoc();
if(chckBox.Checked)
{
documentGenerated = await Task.Run(() => updateDoc()).ConfigureAwait(false);
}
else
{
documentGenerated = await Task.Run(() => newDoc()).ConfigureAwait(false);
}
if(documentGenerated){
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
它抛出了这个错误:
Current thread must be set to single thread apartment (STA) …Run Code Online (Sandbox Code Playgroud) 我想使用一个单独的项目来存储我的测试应用程序的控制器.由于ASP.NET Core工作原理,您需要services.AddMvc().AddApplicationPart使用要添加的程序集进行调用.
我使用Visual Studio 2017(所以不再project.json有)
问题是我无法到达我想要包含的程序集!
我在我的项目中添加了参考:
另外,我决定像AppDomian一样使用polyfill(为了达到我需要的程序集):
public class AppDomain
{
public static AppDomain CurrentDomain { get; private set; }
static AppDomain()
{
CurrentDomain = new AppDomain();
}
public Assembly[] GetAssemblies()
{
var assemblies = new List<Assembly>();
var dependencies = DependencyContext.Default.RuntimeLibraries;
foreach (var library in dependencies)
{
if (IsCandidateCompilationLibrary(library))
{
var assembly = Assembly.Load(new AssemblyName(library.Name));
assemblies.Add(assembly);
}
}
return assemblies.ToArray();
}
private static bool IsCandidateCompilationLibrary(RuntimeLibrary compilationLibrary)
{
return compilationLibrary.Name == ("TrainDiary") …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Simpson在CUDA中的方法对集成进行编码.
这是辛普森统治的公式

哪里x_k = a + k*h.
这是我的代码
__device__ void initThreadBounds(int *n_start, int *n_end, int n,
int totalBlocks, int blockWidth)
{
int threadId = blockWidth * blockIdx.x + threadIdx.x;
int nextThreadId = threadId + 1;
int threads = blockWidth * totalBlocks;
*n_start = (threadId * n)/ threads;
*n_end = (nextThreadId * n)/ threads;
}
__device__ float reg_func (float x)
{
return x;
}
typedef float (*p_func) (float);
__device__ p_func integrale_f = reg_func;
__device__ void integralSimpsonMethod(int totalBlocks, int totalThreads, …Run Code Online (Sandbox Code Playgroud) 我需要能够在我的简单delphi绘制中进行Undo和Redo操作.所以我决定制作一些容器来保存历史记录(不是完整的历史记录,只有少数以前的位图文件).
unit HistoryQueue;
interface
uses
Graphics;
type
myHistory = class
constructor Create(Size:Integer);
public
procedure Push(Bmp:TBitmap);
function Pop():TBitmap;
procedure Clean();
procedure Offset();
function isEmpty():boolean;
function isFull():boolean;
function getLast():TBitmap;
protected
end;
var
historyQueueArray: array of TBitmap;
historyIndex, hSize:Integer;
implementation
procedure myHistory.Push(Bmp:TBitmap);
var tbmp:TBitmap;
begin
if(not isFull) then begin
Inc(historyIndex);
historyQueueArray[historyIndex]:=TBitmap.Create;
historyQueueArray[historyIndex].Assign(bmp);
end else begin
Offset();
historyQueueArray[historyIndex]:=TBitmap.Create;
historyQueueArray[historyIndex].Assign(bmp);
end;
end;
procedure myHistory.Clean;
var i:Integer;
begin
{ for i:=0 to hSize do begin
historyQueueArray[i].Free;
historyQueueArray[i].Destroy;
end; }
end;
constructor myHistory.Create(Size:Integer);
begin
hSize:=Size;
SetLength(historyQueueArray, hSize); …Run Code Online (Sandbox Code Playgroud) Qt开发人员!有没有办法在我的midArea的背景上添加图像,如下图所示?

我知道我可以使用这样的东西
QImage img("logo.jpg");
mdiArea->setBackground(img);
Run Code Online (Sandbox Code Playgroud)
但我不需要在背景上重复我的图像.
谢谢!
我在Delphi中创建了自己的组件(就像一个可以移动的按钮),安装它.然后我从那里创建了一个新项目,并添加了一些新的我的组件元素.但只有最后一个添加才能移动!别人没有.为什么会这样?我该怎么办呢?
这是组件代码:
unit ModifiedButton;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
var Timer: TTimer;
type
TSpeed = (Slow,Normal,Fast);
TModifiedButton = class(TButton)
private
{ Private declarations }
FCount:integer;
Velocity:integer;
FSpeed:TSpeed;
protected
{ Protected declarations }
procedure Click;override;
procedure Move(Vel:Integer);
procedure OnTimer(Sender: TObject);
public
{ Public declarations }
procedure ShowCount;
published
{ Published declarations }
property Count:integer read FCount write FCount;
property Speed: TSpeed read FSpeed write FSpeed;
constructor Create(aowner:Tcomponent); override;
end;
procedure Register;
implementation
procedure Register; …Run Code Online (Sandbox Code Playgroud) 释放javascript之前的实现常量如何ES5?
据我所知,这里没有get/set东西,没有writable财产,没有const文字,没有Object.freeze东西,那么如何使自己的常数不变呢?
例如, Math.PI
如何正确存储n以下功能?因为n在我使用它之后由于某种原因改变了价值.
function Test(n: Integer): Byte;
asm
mov eax, n
add eax, eax
add eax, n
mov ecx, eax
mov ebx, eax
mov ecx, n
end;
Run Code Online (Sandbox Code Playgroud) 好吧,这里出了点问题.我输入我的数据库中存在的用户名和密码.echo在这种情况下它应该是这个字符串
需要激活
但它回应了这一点
你需要注册
的init.php
<?php
//error_reporting(0);
session_start();
require 'dbconnect.php';//this works okay so i wouldn't post this file code
require 'users.php';
$errors = array();
?>
Run Code Online (Sandbox Code Playgroud)
users.php
<?php
function user_exists($username){
$username = mysql_real_escape_string($username);
$query = mysql_query("SELECT COUNT('user_id') FROM `users` WHERE 'username' = '$username'");
if (!$query) {
die('Could not query:' . mysql_error());
}
return (mysql_result($query, 0) == 1) ? true : false;
}
function user_active($username){
$username = mysql_real_escape_string($username);
$querytoo = mysql_query("SELECT COUNT('user_id') FROM `users` WHERE 'username' = '$username' AND 'active' …Run Code Online (Sandbox Code Playgroud) 我正在使用Delphi制作简单的文件管理器.我ListView用来显示文件夹和文件,我使用FileList(它是不可见的)从某个目录中获取文件和文件夹名称.
问题是我想在ListView中不包含这个[.]元素(它是当前目录的符号,不知道为什么Delphi会FileList显示它).但是,当我试图忽略它时(这里是代码)
procedure TfolderFrame.ShowFiles;
var
i: Integer;
size: int64;
fileName, extension: string;
begin
edt1.Text := CurrentFullPath;
lvListView.Clear;
fllstFiles.Directory := CurrentFullPath;
For i := 0 To fllstFiles.Items.Count-1 Do begin
fileName := fllstFiles.Items.Strings[i];
extension := UpperCase(ExtractFileExt(fileName));
size := DSiFileSize(fileName);
Delete(extension, 1, 1);
if (fileName <> '[.]') then begin //error apperas at this line!
if (not(isDirectory(fileName))) then begin
lvListView.Items.Add.Caption := fileName;
lvListView.Items[i].SubItems.Add(IntToStr(size));
lvListView.Items[i].SubItems.Add(extension);
lvListView.Items[i].ImageIndex := GetItemImage(fileName, extension);
end
else begin
Delete(fileName, 1, 1);
Delete(fileName, Length(fileName), …Run Code Online (Sandbox Code Playgroud) 我试图制作简单的纹理,但是出现了一个错误:
错误:'my_texture'没有命名类型
这里出现的地方(LoadTexture方法后面):
GLuint my_texture;
my_texture = LoadTexture( "grass.bmp" );
Run Code Online (Sandbox Code Playgroud)
这是我的代码.怎么了?
#include <iostream>
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h> /* printf, scanf, NULL */
#include <stdlib.h> /* malloc, free, rand */
using namespace std;
float _angle = 0.5f;
GLuint LoadTexture( const char * filename )
{
GLuint texture;
int width, height;
unsigned char * data;
FILE * file;
file = fopen( filename, "rb" );
if ( file == NULL ) return 0;
width = 1024;
height = 512; …Run Code Online (Sandbox Code Playgroud) 试图写简单的客户端和服务器接收/发送数据TMemoryStream.当我在客户端按下按钮时btnTestClick出现错误
Access violation at address 005D5581 in module 'Client.exe'. Write of adress 00000000.我做错了什么?
Btw客户端服务器连接工作正常我瘦cuz IdTCPClient1Connected功能正在写'Client Connected!'.
客户代码
procedure TForm1.btnTestClick(Sender: TObject);
var
msRecInfo: TMemoryStream;
arrOf: array of Integer; i:integer;
begin
for i := 0 to 10 do
arrOf[i]:=random(100);
msRecInfo:= TMemoryStream.Create;
try
msRecInfo.Write(arrOf, SizeOf(arrOf));
idTCPClient1.IOHandler.Write(msRecInfo);
finally
msRecInfo.Free;
end;
end;
end
Run Code Online (Sandbox Code Playgroud)
服务器代码
procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
msRecInfo: TMemoryStream;
arrOf: array of Integer; i:integer;
begin
msRecInfo:= TMemoryStream.Create;
try
AContext.Connection.IOHandler.ReadStream(msRecInfo, -1, False);
msRecInfo.Position := 0;
msRecInfo.Read(arrof, SizeOf(arrof)); …Run Code Online (Sandbox Code Playgroud) delphi ×5
c# ×2
delphi-7 ×2
asp.net ×1
asp.net-core ×1
assembly ×1
basm ×1
bitmap ×1
c++ ×1
constants ×1
cuda ×1
ecmascript-3 ×1
file-manager ×1
filelist ×1
glut ×1
image ×1
integral ×1
javascript ×1
listview ×1
memorystream ×1
mysql ×1
opengl ×1
paint ×1
php ×1
qmdiarea ×1
qt ×1
qt4 ×1
task ×1
tcp ×1
textures ×1
undo-redo ×1