문제

ASP.NET 웹 형식에서 다음과 같은 방법이 있습니다.

public partial class currencies : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{

}

public class Rate
{
    public string to { get; set; }
    public string from { get; set; }
    public double rate { get; set; }
}

double ConvertedAmount { get; set; }

public void Convert(object sender, EventArgs e)
{
    DateTime theDate = DateTime.UtcNow;
    string todayDateTime = theDate.ToString("f");
    double amount = 0d;
    if (double.TryParse(txtAmount.Text.Trim(), out amount))
    {
        string url = string.Format("http://rate-exchange.appspot.com/currency?from={0}&to={1}", ddlFrom.SelectedItem.Value, ddlTo.SelectedItem.Value);
        WebClient client = new WebClient();
        string rates = client.DownloadString(url);
        Rate rate = new JavaScriptSerializer().Deserialize<Rate>(rates);
        ConvertedAmount = amount * rate.rate;
        Label1.Text = ddlFrom.SelectedItem.Value + ": " + amount;
        Label2.Text = ddlTo.SelectedItem.Value + ": " + ConvertedAmount;
        Label3.Text = "Rate as at " + todayDateTime + " is:";
        Label4.Text = " 1 " + ddlFrom.SelectedItem.Value + " = " + rate.rate + " " + ddlTo.SelectedItem.Value;

    }
    else
    {
        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Invalid amount value.');", true);
    }
}


protected void Button1_Click(object sender, EventArgs e)
{   
    Clipboard.SetText(ConvertedAmount.ToString());
}
}
.

단추를 클릭하면 결과를 클립 보드에 복사 할 수 있습니다. OLE를 호출하기 전에 현재 스레드를 단일 스레드 아파트 (STA) 모드로 설정해야합니다.이런 식으로 처음 거래하는 것은 처음입니다. 이 문제를 해결하기 위해 내가해야 할 일은 무엇입니까?도움을 주셔서 감사합니다.

도움이 되었습니까?

해결책

as "Nofollow"> MSDN. 상태,

클립 보드 클래스는 단일 스레드로 설정된 스레드에서만 사용할 수 있습니다. 아파트 (STA) 모드.

ASP.NET의 STA 설정은 필요하지 않아야합니다.그러나 서버 측의 클립 보드에서 작동 하시겠습니까?클라이언트가 아닌 서버 클립 보드에서 작동 할 것이라는 것을 이해합니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top